我有三个xml文件
<step>
<Products>
<Product UserTypeID="Country">
<Name>Cyprus</Name>
<Product UserTypeID="Resort">
<Name>Argaka</Name>
<Product UserTypeID="Property">
<Name>Villa Tester</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Coral Bay</Name>
<Product UserTypeID="Property">
<Name>1</Name>
</Product>
<Product UserTypeID="Property">
<Name>2</Name>
</Product>
</Product>
</Product>
<Product UserTypeID="Country">
<Name>Greece</Name>
<Product UserTypeID="Region">
<Name>Corfu</Name>
<Product UserTypeID="Resort">
<Name>Aghios Stefanos</Name>
<Product UserTypeID="Property">
<Name>Villa Joanna</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa Eleonas</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Kassiopi</Name>
<Product UserTypeID="Property">
<Name>Villa 2</Name>
</Product>
</Product>
</Product>
</Product>
</Products>
<step>
<Products>
<Product UserTypeID="Country">
<Name>Cyprus</Name>
<Product UserTypeID="Resort">
<Name>Argaka</Name>
<Product UserTypeID="Property">
<Name>Villa Jaime</Name>
</Product>
</Product>
</Product>
<Product UserTypeID="Country">
<Name>Greece</Name>
<Product UserTypeID="Region">
<Name>Corfu</Name>
<Product UserTypeID="Resort">
<Name>Acharavi</Name>
<Product UserTypeID="Property">
<Name>Villa 1</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa 2</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Gouvia</Name>
<Product UserTypeID="Property">
<Name>Villa De Bono</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Kassiopi</Name>
<Product UserTypeID="Property">
<Name>Villa 1</Name>
</Product>
</Product>
</Product>
</Product>
</Products>
<step>
<Products>
<Product UserTypeID="Country">
<Name>Cyprus</Name>
<Product UserTypeID="Resort">
<Name>Aghia Marina</Name>
<Product UserTypeID="Property">
<Name>Villa Aghia Marina</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Coral Bay</Name>
<Product UserTypeID="Property">
<Name>Ascos Coral Villas</Name>
</Product>
<Product UserTypeID="Property">
<Name>Coral Villa</Name>
</Product>
<Product UserTypeID="Property">
<Name>Lella Villas</Name>
</Product>
</Product>
</Product>
<Product UserTypeID="Country">
<Name>Greece</Name>
<Product UserTypeID="Region">
<Name>Corfu</Name>
<Product UserTypeID="Resort">
<Name>Acharavi</Name>
<Product UserTypeID="Property">
<Name>Villa Angelos</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa Eleonas</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Aghios Stefanos</Name>
<Product UserTypeID="Property">
<Name>Villa Joanna</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa Eleonas</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Kassiopi</Name>
<Product UserTypeID="Property">
<Name>Villa Imerolia</Name>
</Product>
<Product UserTypeID="Property">
<Name>Test Property</Name>
</Product>
</Product>
</Product>
</Product>
</Products>
每个文件都有相同的产品(按./name),但有不同的子产品(按./name),我需要将它们连接成一棵树,每个产品/名称一个产品,包含相同规则的所有子产品,以便我可以输出一种结构。
我找到了一个 xslt 方法,它将创建一个节点集,如下所示
<xsl:variable name="step-output">
<xsl:for-each select="/index/file">
<xsl:copy-of select="document(.)" />
</xsl:for-each>
</xsl:variable>
<xsl:variable name="step-products" select="exsl:node-set($step-output)//Products" />
但是,当我创建其他模板时,将按产品/名称创建三个产品,即塞浦路斯将出现三次。
有谁知道我要怎么做??我的结果需要如下
<step>
<Products>
<Product UserTypeID="Country">
<Name>Cyprus</Name>
<Product UserTypeID="Resort">
<Name>Aghia Marina</Name>
<Product UserTypeID="Property">
<Name>Villa Aghia Marina</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Argaka</Name>
<Product UserTypeID="Property">
<Name>Villa Jaime</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa Tester</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Coral Bay</Name>
<Product UserTypeID="Property">
<Name>Ascos Coral Villas</Name>
</Product>
<Product UserTypeID="Property">
<Name>Coral Villa</Name>
</Product>
<Product UserTypeID="Property">
<Name>Lella Villas</Name>
</Product>
<Product UserTypeID="Property">
<Name>1</Name>
</Product>
<Product UserTypeID="Property">
<Name>2</Name>
</Product>
</Product>
</Product>
<Product UserTypeID="Country">
<Name>Greece</Name>
<Product UserTypeID="Region">
<Name>Corfu</Name>
<Product UserTypeID="Resort">
<Name>Acharavi</Name>
<Product UserTypeID="Property">
<Name>Villa Angelos</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa Eleonas</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa 1</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa 2</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Aghios Stefanos</Name>
<Product UserTypeID="Property">
<Name>Villa Joanna</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa Eleonas</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Gouvia</Name>
<Product UserTypeID="Property">
<Name>Villa De Bono</Name>
</Product>
</Product>
<Product UserTypeID="Resort">
<Name>Kassiopi</Name>
<Product UserTypeID="Property">
<Name>Villa Imerolia</Name>
</Product>
<Product UserTypeID="Property">
<Name>Test Property</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa 1</Name>
</Product>
<Product UserTypeID="Property">
<Name>Villa 2</Name>
</Product>
</Product>
</Product>
</Product>
</Products>