XSLT <xsl:apply-templates>
❮ Kompletní reference prvků XSLT
Definice a použití
Prvek <xsl:apply-templates> aplikuje šablonu na aktuální prvek nebo na podřízené uzly aktuálního prvku.
Pokud do prvku <xsl:apply-templates> přidáme atribut select, zpracuje se pouze podřízený prvek, který odpovídá hodnotě atributu. Pomocí atributu select můžeme určit, v jakém pořadí mají být podřízené uzly zpracovávány.
Syntax
<xsl:apply-templates select="expression" mode="name">
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
Atributy
Attribute | Value | Description |
---|---|---|
select | expression | Optional. Specifies the nodes to be processed. An asterisk selects the entire node-set. If this attribute is omitted, all child nodes of the current node will be selected |
mode | name | Optional. If there are multiple ways of processing defined for the same element, distinguishes among them |
Příklad 1
Obalte jeden prvek h1 kolem každého prvku title v dokumentu:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="title">
<h1><xsl:apply-templates/></h1>
</xsl:template>
</xsl:stylesheet>
Příklad 2
Obalte jeden prvek h1 kolem všech prvků title, které jsou potomky zprávy:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="title"/></h1>
</xsl:template>
</xsl:stylesheet>
Příklad 3
Obalte jeden prvek h1 kolem všech podřízených uzlů zprávy, které mají atribut mode nastavený na „velký“:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="*" mode="big"/></h1>
</xsl:template>
</xsl:stylesheet>
❮ Kompletní reference prvků XSLT