Quantcast
Channel: XPath relative path in expression - Stack Overflow
Viewing all articles
Browse latest Browse all 5

XPath relative path in expression

$
0
0

I am in 'group' node. From it, I want to find such 'item' node, that has 'id' attribute equals to current's 'group' node 'ref_item_id' attribute value. So in my case, by being in 'group' node B, I want 'item' node A as output. This works:

<xsl:value-of select="preceding-sibling::item[@id='1']/@description"/>

But this doesn't (gives nothing):

<xsl:value-of select="preceding-sibling::item[@id=@ref_item_id]/@description"/>

When I type:

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

I have '1' as result. So this attribute is for sure accessible, but I can't find path to it from XPath expression above. I tried many '../' combinations, but couldn't get it work.

Code to test: http://www.xmlplayground.com/7l42fo

Full XML:

<?xml version="1.0" encoding="UTF-8"?><root><item description="A" id="1"/><item description="C" id="2"/><group description="B" ref_item_id="1"/></root>

Full XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="text" indent="no"/><xsl:template match="root"><xsl:for-each select="group"><xsl:value-of select="preceding-sibling::item[@id=@ref_item_id]/@description"/></xsl:for-each></xsl:template></xsl:stylesheet>

Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images