deleyd
asked on
XSLT 2.0 match attribute of parent to attribute somewhere else
I have some XML data that looks something like this:
I now want to test if the id= above me matches any href= in section <B> above. (To make it simple there's only one level below <B>.)
[Earlier when I was on node <X>, I was able to write the following test:]
<A>
<B>
<C href="#hello"/>
</B>
...
<X id="hello">
<Y>
...
I'm running an XSLT 2.0 transformation, and I'm on node <Y>. I know there's a parent node <X> above me with an id= attribute, and I suspect there's a section <B> above which has a bunch of child nodes, not necessarily <C> nodes, they may be anything, but they may have an href= attribute that points to the <X id=...> above me.I now want to test if the id= above me matches any href= in section <B> above. (To make it simple there's only one level below <B>.)
[Earlier when I was on node <X>, I was able to write the following test:]
<xsl:when test="/A/B/*[./@href = current()/concat('#',@id)]
Pretty close to what I now need, except I need to replace current() with parent(), or parent::, and that's where I'm losing the syntax.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NodeList nodelist=doc.geyElementByTagName(A);
for(int i=0;i<nodelist.getLenght();i++)
{
Node node=nodelist.item(i);
NodeList nl=node.getchildNode();
for(int j=0;j<nl.getlenght();j++)
{
Node nodes=nl.item(j);
if(nodes.getnodename().equals("B")
{
//do Operation for B
}
if(nodes.getchildnode().equals("X))
{
//Do Opration for X
}
@manoj kumar
interesting XSLT 2.0 ;-)
interesting XSLT 2.0 ;-)
ASKER
Works like a charm! Thank you!
welcome
Try
<xsl:when test="/A/B/*[./@href = current()/parent::*/concat
but I would use a key