tesmc
asked on
How to grab found parent node and only its relevant child nodes
I have xsl with help from EE that searches for a country within another node and if found returns the parent and all of its contents
however, the parent contains many sub-zones, i dont want to return the sub-zones that don't contain the country i was initially searching for.
please assist.
input.xml
Output.xml
test1.xsl
however, the parent contains many sub-zones, i dont want to return the sub-zones that don't contain the country i was initially searching for.
please assist.
input.xml
Output.xml
test1.xsl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Gertone:
i also wanted to ask how would you resolve the issue where the country i was searching for exists in both sub-zones, but i only want the 2nd instance of it?
i also wanted to ask how would you resolve the issue where the country i was searching for exists in both sub-zones, but i only want the 2nd instance of it?
copy-of makes a deep copy of the selected node(set)
<xsl:copy-of select="key('sub-zone', $country)"/> copies the sub-zone which I get back from using the key() function
<xsl:copy-of select="key('sub-zone', $country)/ancestor::zone[1 ]/@*"/> copies a different node. It selects the same sub-zone to start with, travels to the ancestor (that are the elements higher up the hierrachy) with the name "zone", takes the first one it encounters, and then selects all its attributes
So the first copy-of in the xslt copies the attributes of the parent, the second copy-of copies the entire sub-zone
<xsl:copy-of select="key('sub-zone', $country)"/> copies the sub-zone which I get back from using the key() function
<xsl:copy-of select="key('sub-zone', $country)/ancestor::zone[1
So the first copy-of in the xslt copies the attributes of the parent, the second copy-of copies the entire sub-zone
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Gertone:
yes your last code snippet definetly worked.
can you please explain how? (i'm a newbie to xsl, so am learning as i go)
yes your last code snippet definetly worked.
can you please explain how? (i'm a newbie to xsl, so am learning as i go)
key('sub-zone', $country) will return all subzones
[] adds a predicate in which you can define some restrictions
last() is short for position() = last()
key('sub-zone', $country)[last()]
will select the last sub-zone from teh selected sub-zones
[] adds a predicate in which you can define some restrictions
last() is short for position() = last()
key('sub-zone', $country)[last()]
will select the last sub-zone from teh selected sub-zones
ASKER
Can you please explain why in the GetZonesTemp template you do a copy-of select 2x?
<xsl:copy-of select="key('sub-zone', $country)/ancestor::zone[1
<xsl:copy-of select="key('sub-zone', $country)"/>
the result is correct, but I'd like to understand what this ancestor feature does and why you wouldn't get dups given that you copy-select twice