14

I don't understand what we mean by the following:

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

Please help me out..

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

If I apply like this it is omitting the <status> node in my XML, how is this happening?

Will Webb
  • 795
  • 6
  • 20
Ironman
  • 556
  • 3
  • 7
  • 21

1 Answers1

20

/|@*|node() is a match pattern composed of three single patterns. / matches a root node, also called document node, @* matches any attribute node and node() as a pattern "matches any node other than an attribute node and the root node". So for any kind of node (as those three patterns describe all types of nodes) the template says <xsl:apply-templates select="@*|node()"/> which means process the union of the attribute nodes and the child nodes. Document nodes matched by / don't have attribute nodes and attributes don't have them either but as a compact way you often see templates like that.

However there is a built-in template for document nodes that does <xsl:template match="/"><xsl:apply-templates/></xsl:template> so usually people omit the / in the pattern.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Also, the `match` in `xsl:apply-templates` should be `select`. – Daniel Haley Nov 16 '12 at 18:31
  • If i apply like this it is omitting the node in my xml,howz it happening – Ironman Nov 16 '12 at 18:52
  • DevNull, thanks for pointing out the error in the `apply-templates` snippet, I have now corrected that. – Martin Honnen Nov 17 '12 at 10:40
  • Srivatsava Sesham, if you have problems with one particular input document and XSLT then please consider to start a new question, clearly showing us all the relevant code (XML input, XSLT you have, output you want, output you currently get). – Martin Honnen Nov 17 '12 at 10:42