Reputation: 367
Just want to know how to read an attribute of a parent node(A) from a child node(c) in XSLT. code:
<A attr1="xx">
<b>
<c>
</c>
</b>
</A>
XSLT:
<xsl:template match="c">
<xsl:value-of select="attribute of A node">
</xsl:template>
Upvotes: 1
Views: 635
Reputation: 70598
A
is not actually the parent of c
but an ancestor (b
is the parent!), but the code you are looking for is this
<xsl:value-of select="ancestor::A/@attr1">
(You could replace ancestor
with parent
in the case A
was the direct parent of c
)
You could also do this:
<xsl:value-of select="../../@attr1">
But this would assume A
is always the 'grand-parent` (i.e. the parent of the parent).
Upvotes: 3