Noodles
Noodles

Reputation: 928

How to get value of attribute inside an element

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

Upvotes: 1

Views: 279

Answers (1)

bob.faist
bob.faist

Reputation: 728

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

Just needs a slash in the XPath before @name.

Upvotes: 4

Related Questions