tags:

views:

406

answers:

1

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>
+5  A: 

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

<xsl:value-of select="../@attr1"/>
Adam Batkin
yeah just now coded //@attr1 and it worked for me...anyways thanks for ur help.
Wondering
@Wondering - the expression "//@attr1" will scan the ENTIRE document (and won't stop even when it finds the first match). This is very inefficient and could grab the wrong @attr1(if you have that attribute in other places). @Adam Batkin's solution is more efficient and less likely to accidentally select the wrong value.
Mads Hansen
@Mads: Thanks for ur inputs and information,will implement the same
Wondering