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>
<xsl:template match="node()"> is an abbreviation for: <xsl:template match="child::node()"> This matches any node type that can be selected via the child:: axis: element. text-node.
A Parent of a context node is selected Flat element. A string of elements is normally separated by a slash in an XPath statement. You can pick the parent element by inserting two periods “..” where an element would typically be. The parent of the element to the left of the double period will be selected.
A Node that is the parent of the current node. The parent of an element is an Element node, a Document node, or a DocumentFragment node.
The xsl:attribute element is used to add an attribute value to an xsl:element element or literal result element, or to an element created using xsl:copy. The attribute must be output immediately after the element, with no intervening character data. Available in XSLT 1.0 and later versions.
You can go "up" a level using "..
". So:
<xsl:value-of select="../@attr1"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With