tags:

views:

40

answers:

1

I want to get an attribute from another element.

E.g.

<xsl:template match="tag1">
  Test: <xsl:value-of select="inner[@class='test']@name"/>
</xsl:template>

XML:

<xml>
  <tag1>
    <inner class="something" name="123"/>
    <inner class="test" name="456"/>
  </tag1>
</xml>

So what I'm expecting is to get

Test: 456

Obviously the XSLT above doesn't work, but that's what it should logically be. Can someone help me?

Thanks

+4  A: 
<xsl:value-of select="inner[@class='test']/@name"/>

Just needs a slash in the XPath before @name.

bob.faist
Thanks, that got it
Noodles