XSLT <xsl:aplicar-plantillas>
❮ Referencia completa del elemento XSLT
Definición y uso
El elemento <xsl:apply-templates> aplica una plantilla al elemento actual oa los nodos secundarios del elemento actual.
Si agregamos un atributo de selección al elemento <xsl:apply-templates>, procesará solo el elemento secundario que coincida con el valor del atributo. Podemos usar el atributo de selección para especificar en qué orden se procesarán los nodos secundarios.
Sintaxis
<xsl:apply-templates select="expression" mode="name">
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
Atributos
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 |
Ejemplo 1
Envuelva un solo elemento h1 alrededor de cada elemento de título en el documento:
<?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>
Ejemplo 2
Envuelva un solo elemento h1 alrededor de todos los elementos de título que son elementos secundarios del mensaje:
<?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>
Ejemplo 3
Envuelva un solo elemento h1 alrededor de todos los nodos secundarios del mensaje que tienen el atributo de modo establecido en "grande":
<?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>
❮ Referencia completa del elemento XSLT