I recently asked a question regarding how to ignore multiple elements, and got some good responses regarding using 'preceding' and the Muenchian Method. However I was wondering whether it is possible to do this across multiple files, with an index xml file.
Index.xml
<?xml-stylesheet type="text/xsl" href="merge2.xsl"?>
<list>
<entry name="File1.xml" />
<entry name="File2.xml" />
</list>
Example of XML file
<Main>
<Records>
<Record>
<Description>A</Description>
</Record>
<Record>
<Description>A</Description>
</Record>
<Record>
<Description>B</Description>
</Record>
<Record>
<Description>C</Description>
</Record>
</Records>
<Records>
<Record>
<Description>B</Description>
</Record>
<Record>
<Description>A</Description>
</Record>
<Record>
<Description>C</Description>
</Record>
<Record>
<Description>C</Description>
</Record>
</Records>
</Main>
Merge2.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes" />
<xsl:key name="Record-by-Description" match="Record" use="Description"/>
<xsl:template match="@* | node()">
<xsl:apply-templates select="@* | node()"/>
</xsl:template>
<xsl:template match="Main">
<table>
<tr>
<th>Type</th>
<th>Count</th>
</tr>
<xsl:apply-templates select="Records"/>
</table>
</xsl:template>
<xsl:template match="Records">
<xsl:apply-templates select="Record[generate-id() = generate-id(key('Record-by-Description', Description)[1])]" mode="group"/>
</xsl:template>
<xsl:template match="Record" mode="group">
<tr>
<td>
<xsl:value-of select="Description"/>
</td>
<td>
<xsl:value-of select="count(key('Record-by-Description', Description))"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
This works fine on one file, and gives me the desired result of producing one table, with unique items only being displayed and the count being added. However I have been unable to produce the desired result when going through the index.xml for multiple files.
I have tried using a seperate template targeting the index.xml and applying the 'Main' template to the different XML files, and also tried using a for-each to cycle through the different files.
Before being introduced to the Muenchian Method I was using for-each with 'preceding' to check for duplicate nodes, however 'preceding' only seems to search back through the current document and have been unable to find information on using this across multi documents.
Is it possible with either of these methods to be able to search through multiple documents for duplicated element text?
Many thanks for any help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…