我最近問了一個關於如何忽略多個元素的問題,並且得到了關於使用'在前'和Muenchian方法的一些很好的回答。但是我想知道是否有可能通過索引xml文件在多個文件中執行此操作。XSLT忽略多個文件中的重複元素
INDEX.XML
<?xml-stylesheet type="text/xsl" href="merge2.xsl"?>
<list>
<entry name="File1.xml" />
<entry name="File2.xml" />
</list>
XML文件的示例
<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>
能正常工作的一個文件,並給我產生的理想結果一張桌子,只顯示唯一的項目並添加計數。但是,當我通過index.xml查看多個文件時,我一直無法產生所需的結果。
我試過使用一個單獨的模板來定位index.xml,並將'Main'模板應用於不同的XML文件,並嘗試使用for-each來遍歷不同的文件。
在引入Muenchian方法之前,我使用for-each和'preceding'來檢查重複節點,但是'之前'似乎只能通過當前文檔進行搜索,並且無法找到有關使用此方面的信息跨多個文檔。
這些方法中的任何一種都可以通過多個文檔搜索重複元素文本嗎?
非常感謝您的幫助。
非常感謝你,這個工程就像預期。 – user2795778