Compare parent's attribute with grand parent's one
Hi,
I wanted to compare an element's parent's name attribute with it's grand parent's name attribute. If they match I wanted to print something. The XPath query I used is this, but apparently it didn't work:
<xsl:when test="..[@name]=../..[@name]">
Edit: I see now that it is a wrong syntax.
Here is my XML structure:
<RootElement>
<Groups name='top1'>
<Group name='sub1'>
<Groups name='sub1'>
<Group name="sub1ofsub1"/>
<Group name="sub2ofsub1"/>
<Group name="sub3ofsub1"/>
</Groups>
<Group>
<Groups>
</RootElement>
I can achieve my goal with defining variables for name attributes and comparing them, but if there is a Xpath structure I can use I'd prefere one line code rather than variables.
Thanks in advance.
EDIT: I thought it would be easy to do what I want with variables but I wasn't even able to do that. There is no runtime variable assignment in XSL, which makes things harder.
Here is the XSL structure I tried to get values ( I assume I'm in one of the inner Group elements):
<xsl:template match="Group">
<xsl:variable name="parentsname">
<xsl:value-of select="..[name()='Groups']/[@name]"/>
</xsl:variable>
<xsl:variable name="grandparentsname">
<xsl:value-of select="..[name()='Groups']/..[name()='Group']/[@name]"/>
</xsl:variable>
</xsl:template>
so far I wasn't able to make it work.
|