10

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

1 Answer 1

18
<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.

Sign up to request clarification or add additional context in comments.

3 Comments

and local-name() do get the name without namespace
Thanks a lot for suggestions but i just put a dummy expression to explain my question but yup i am abs agree with you on this :)
Never mind, I say something about the // almost every time I see it. ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.