Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default select of XSLT apply-templates?

Tags:

xslt

xslt-2.0

The identity template looks like this:

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
</xsl:template>

Does <xsl:apply-templates select="@*|node()" /> select more than <xsl:apply-templates />, or could the identity template have been like this?

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates />
    </xsl:copy>
</xsl:template>

What exactly is selected when I do the following?

<xsl:apply-templates />
like image 967
Svish Avatar asked Oct 03 '12 11:10

Svish


People also ask

What is apply-templates in XSLT?

The <xsl:apply-templates> element applies a template to the current element or to the current element's child nodes. If we add a "select" attribute to the <xsl:apply-templates> element, it will process only the child elements that matches the value of the attribute.

What is XSLT template name?

The xsl:template element is used to create a template. You can name a template by using the name attribute of the xsl:template element. Further, the name called by the mandatory name attribute of the xsl:call-template element must match the name specified by the name attribute of the xsl:template element.

What is XSLT format?

The Extensible Stylesheet Language Transformation (XSLT) standard specifies a language definition for XML data transformations. XSLT is used to transform XML documents into XHTML documents, or into other XML documents.

What is the meaning of xsl template match ()?

XSLT <xsl:template> The match attribute is used to associate the template with an XML element. The match attribute can also be used to define a template for a whole branch of the XML document (i.e. match="/" defines the whole document).


2 Answers

Does <xsl:apply-templates select="@*|node()" /> select more than <xsl:apply-templates />, or could the identity template have been like this?

<xsl:apply-templates/> 

is equivalent to:

<xsl:apply-templates select="node()"/>

and this is a shorter former of:

<xsl:apply-templates select="child::node()"/>

and this is a equivalent to:

<xsl:apply-templates select="* | text() | comment() | processing-instruction()"/>

As we see from the last instruction, the xsl:apply-templates instruction you are asking about, doesn't select any attributes, therefore it cannot be used as a shorthand for:

<xsl:apply-templates select="@*|node()"/>
like image 57
Dimitre Novatchev Avatar answered Oct 10 '22 14:10

Dimitre Novatchev


The default select for <xsl:apply-templates/> is just "node()", it doesn't include attributes.

like image 22
Ian Roberts Avatar answered Oct 10 '22 13:10

Ian Roberts