this get ever more complicated 🙂
now i face another issue in last question we managed to take unique values from only one parent node
now with:
<?xml version="1.0" encoding="ISO-8859-1"?>
<roots>
<root>
<name>first</name>
<item>
<something>A</something>
<something>A</something>
</item>
<item>
<something>B</something>
<something>A</something>
</item>
<item>
<something>C</something>
<something>P</something>
</item>
<item>
<something>A</something>
<something>L</something>
</item>
<item>
<something>A</something>
<something>A</something>
</item>
<item>
<something>B</something>
<something>A</something>
</item>
<item>
<something>D</something>
<something>A</something>
</item>
</root>
<root>
<name>second</name>
<item>
<something>E</something>
<something>A</something>
</item>
<item>
<something>B</something>
<something>A</something>
</item>
<item>
<something>F</something>
<something>A</something>
</item>
<item>
<something>A</something>
<something>A</something>
</item>
<item>
<something>A</something>
<something>A</something>
</item>
<item>
<something>B</something>
<something>H</something>
</item>
<item>
<something>D</something>
<something>G</something>
</item>
</root>
</roots>
now i need to get the unique values depending only from one node before but just from the elements on the second position
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="text"/>
<xsl:key name="item-by-value" match="something"
use="concat(normalize-space(.), ' ', generate-id(./ancestor::root))"/>
<xsl:key name="rootkey" match="root" use="name"/>
<xsl:template match="/">
<xsl:for-each select="key('rootkey','first')">
<xsl:for-each select="item/something[1]">
<xsl:sort />
<xsl:if test="generate-id() = generate-id(key('item-by-value',
concat(normalize-space(.), ' ', generate-id(./ancestor::root))))">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
<xsl:text>_________</xsl:text>
<xsl:for-each select="item/something[2]">
<xsl:sort />
<xsl:if test="generate-id() = generate-id(key('item-by-value',
concat(normalize-space(.), ' ', generate-id(./ancestor::root))))">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
with this XSL i get ABCD_________LP
where the result i need is ABCD_________ALP
any ideas?
Once again, the issue is that if you want to say “the first node with this content under this root appearing in this position in the
itemnode“, then you have to add “position in theitemnode” to the key. You can either do this by having two separate keys, as Dimitre’s solution does, or change your key to:And then make your two test expressions look like:
and: