I have several XML documents. Each one of these documents has some elements with the same name (let's say ).
An example of two of these XML documents would be (simplifying):
input1.xml
<xml>
<body>
<word>A1</word>
<word>A2</word>
<word>B1</word>
</body>
</xml>
and
input2.xml
<xml>
<body>
<word>A2</word>
<word>B1</word>
<word>B2</word>
</body>
</xml>
I need (via XSLT 1.0) to sort all elements of the two files, avoiding repetitions.
The output file I need is:
output1.xml
<xml>
<body>
<word>A1</word>
<word>A2</word>
<word>B1</word>
<word>B2</word>
</body>
</xml>
I have tried to do it naming the input files as parameters in the XSLT file:
<xsl:param name="doc1">input1.xml</xsl:param>
<xsl:param name="doc2">input2.xml</xsl:param>
Then I created a element:
<xsl:key name="words" match="word" use="."/>
And I applied some templates to the elements of a combination of the two files, like this:
<xsl:apply-templates select="(document($doc1)|document($doc2))//body"/>
Finally, in the template I used the above created key for applying the Muenchian approach:
<xsl:template match="body">
<xsl:for-each select="//hitza[generate-id() = generate-id(key('words',.)[1])]
<xsl:sort select="."/>
<xsl:value-of select="."/>
</xsl:for-each>
</xsl>
This way I get a list of elements, but first I get all the elements of the input1.xml file, and then the elements of the input2.xml file:
<xml>
<body>
<word>A1</word>
<word>A2</word>
<word>B1</word>
<word>A2</word>
<word>B1</word>
<word>B2</word>
</body>
</xml>
I can't figure out how to get a list of non-repeated items from the two files.