2

I'm editing an XSL file, and having trouble getting the name of an element.

Everything here works except for ../../name(). What I'm trying to do there is get the name of the element. Everything beneath it successfully gets the attributes of that same element, so hopefully the fact that ../../@name (etc.) works should make clear what I'm trying to do with ../../name().

<tr>
<td><xsl:value-of select="../../name()" /></td>
<td><xsl:value-of select="../../@name"/></td>
<td><xsl:value-of select="../../@alias"/></td>
<td><xsl:value-of select="../../@comment"/><xsl:text>...</xsl:text></td>
<td><xsl:value-of select="../../dxl:wassignedby" /></td> 
<td><xsl:apply-templates select="."/></td>
</tr>

The piece of XML (in case it helps you visualize what I'm talking about) is:

<form name="Extended Content" alias="CONTENT" hide="notes" nocompose="true" noquery="true" publicaccess="false" designerversion="8">

I'm successfully getting (e.g.) "Extended Content" with ../../@name, but not getting "form" with ../../name().

iconoclast
  • 21,213
  • 15
  • 102
  • 138

2 Answers2

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

Works only in XPath 2.0 where:

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

works in both XPath 1.0 and 2.0. So I guess you are running XPath 1.0 and you should use the latter one.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
2

You need to pass in a parameter to name(). The param to pass to name would be

name(.)

the period means current node. Here is a link that explains it better. Is there an XSLT name-of element?

Community
  • 1
  • 1
Jack Thor
  • 1,554
  • 4
  • 24
  • 53
  • Thanks for the help. I was aware of the existence of `name()` but I couldn't get it to work. So it's not a duplicate. – iconoclast Aug 20 '13 at 14:32
  • @iconoclast ok I removed it. – Jack Thor Aug 20 '13 at 16:04
  • @JackThor I felt the inclusion of the link to the other question was really good because it also mentioned `local-name` which in reading the answers to that question is usually the best way to get an element name. So I would either include information about that or add the link back in. – Matthew Green Aug 20 '13 at 16:16