Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xslt

xpath

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> 
like image 934
Wondering Avatar asked Sep 11 '09 08:09

Wondering


People also ask

What is node() in XSLT?

<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.

How do I navigate to parent node in XPath?

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.

What is parent node?

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.

What is attribute in XSLT?

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.


1 Answers

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

<xsl:value-of select="../@attr1"/> 
like image 77
Adam Batkin Avatar answered Sep 25 '22 14:09

Adam Batkin