I am very new to XSL and I am confused about what the select inside the following pieces of code will select.
<xsl:apply-templates select="."/>
<xsl:apply-templates select="*|@*"/>
Any ideas? Thanks
Definition and Usage 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 element that matches the value of the attribute.
XSLT apply-templates define how to find elements and help in removing unwanted text in the document. It applies a template rule to the current child nodes. It adds a select attribute along with the template to specify the order of child nodes to process the current task with the help of the XSLT processor.
Definition of XSLT Template. XSLT Template defines a way to set rules to generate the desired Output in a proper structure for a particular context and to build a template. The template tells the XSLT processor how to format a particular output from the XML source document.
Definition and Usage The <xsl:value-of> element extracts the value of a selected node. The <xsl:value-of> element can be used to select the value of an XML element and add it to the output.
Check out the Abbreviated Syntax section of XPath 2.0.
In the <xsl:apply-templates select="."/>
example, .
evaluates to the context item. In most cases, this is the same as the node currently being processed. So this example will select the context node.
In the <xsl:apply-templates select="*|@*"/>
example, *
will select all the child elements of the context node. @*
will select all the attributes of the context node. |
is the union operator. So this example will select all the child elements of the context node and also all the attributes of the context node.
<xsl:apply-templates select="."/>
is frequently used to apply further processing to the context node.
<xsl:apply-templates select="*|@*"/>
is frequently used to process all the child elements of the current node and its attributes. It’s often used when you’re done handling an element and want to hand off its child elements/attributes to any other templates that apply.
<xsl:apply-templates select="."/>
processes the content of the current node! the dot .
indicates content.. if the current node doesn't have childnodes but has data instead (ex: <foo>Sample Data</foo>
) then the parser processes the data Sample Data
<xsl:apply-templates select="@*|*"/>
processes the attribute and child nodes or the data under the current node.. difference is .. this one takes care of all the attribute of the context node..
I use the word process
instead of copy
, because .. apply-template
unlike copy-of
and value-of
evaluates other templates, for example along with above code if I have one more template like below:
<xsl:template match="text()[.='Sample Data']"/>
then it will drop the text from your output XML. Where as copy-of select="node_name"
and value-of select="node-name"
copy the data despite of being this template in our XSL file..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With