Wondering
Wondering

Reputation: 5076

How to read attribute of a parent node from a child node in XSLT

Just want to know how to read an attribute of a parent node from a child node in XSLT. code:

<A>
  <b attr1="xx">
    <c>
    </c>
  </b>
</A>

XSLT:

<xsl:template match="c">
  <xsl:value-of select="attribute of b node">
</xsl:template>

Upvotes: 49

Views: 66933

Answers (1)

Adam Batkin
Adam Batkin

Reputation: 52954

You can go "up" a level using "..". So:

<xsl:value-of select="../@attr1"/>

Upvotes: 100

Related Questions