Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selecting current element name in XSLT

Tags:

xslt

xpath

I need to output the element name which is being returned after applying the xpath expression for example

<xsl:for-each select="//element">
      <xsl:value-of select="**{elementname}**"></xsl:value-of>
      <xsl:text>:</xsl:text>
      <xsl:value-of select="current()"/>
      <xsl:value-of />
</xsl:for-each>

How can i replace {elementname} to some xpath so that I can get the element name instead of current value

like image 366
Gripsoft Avatar asked Jan 28 '10 12:01

Gripsoft


People also ask

What does node () mean in XSLT?

This is called the identity transform. The node()|@* is matching all child nodes ( node() is all text,element,processing instructions,comments) and attributes ( @* ) of the current context.

Which symbol is used to get the element value in XSLT?

XSLT <xsl:value-of> Element The <xsl:value-of> element is used to extract the value of a selected node.

What is local name () in XSLT?

XSLT/XPath Reference: XSLT elements, EXSLT functions, XPath functions, XPath axes. The local-name function returns a string representing the local name of the first node in a given node-set.

What is value of select in XSLT?

The XSLT <xsl:value-of> element is used to extract the value of selected node. It puts the value of selected node as per XPath expression, as text.


1 Answers

<xsl:value-of select="name()" />

Side note: Avoid the // shorthand unless you absolutely have no other possibility. It seems quick and easy, but it isn't - it is computationally very expensive, and 90% of the time you don't need it.

Write a canonical replacement XPath expression whenever you can. Even something as generic as /*/*/node runs much faster than //node.

like image 180
Tomalak Avatar answered Sep 28 '22 11:09

Tomalak