我知道这个问题之前已经提出但无法获得任何以前提供的解决方案来处理我的XML。
我的XML文档如下。我的要求是为每个"产品"生成一个简单的html表。元素和他们各自的" pa:RepaymentFrequency"和" pa:RepaymentType"元素。
" pa:RepaymentFrequency"和" pa:RepaymentType"元素在每个"产品"中重复。元素和我的要求是摆脱" pa:RepaymentFrequency"的重复。和" pa:RepaymentType"。请注意" pa:RepaymentFrequency"和" pa:RepaymentType"根据其属性节点"值"确定。我正在使用XSLT 1.0获取您的信息。
例如
<pa:RepaymentFrequency value="Weekly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Fortnightly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Monthly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Monthly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Weekly"></pa:RepaymentFrequency>
一旦摆脱了重复
<pa:RepaymentFrequency value="Weekly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Fortnightly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Monthly"></pa:RepaymentFrequency>
同样应该是。
(1)我曾尝试与&#34; Muenchian&#34;如下。
<xsl:template-match="Product">
<tr>
<td>
<xsl:for-each select=".//pa:RepaymentFrequency[generate-id()
= generate-id(key('product-group', @value)[1]]">
<xsl:value-of-select="."/>
</xsl:for-each>
</td>
</tr>
</xsl:template>
(2)还试过以下
<xsl:template match="Product">
<tr>
<xsl:variable name="distinct_values" select=".//pa:RepaymentFrequency/@value[not(preceding::pa:RepaymentFrequency/@value = .)]"/>
<xsl:for-each select="$distinct_values">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:apply-templates/>
</tr>
</xsl:template>
在这两种情况下,它都适用于XML文档中遇到的第一个元素,而不适用于其他元素(两种方法都输出相同的XML)。
非常感谢任何帮助。
我的XML如下。
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<OldProducts>
<Product display="###" productcode="###" productname="###" longname="###">
<pa:RepaymentType value="###"></pa:RepaymentType>
<pa:RepaymentType value="###"></pa:RepaymentType>
<pa:TotalTerm minInclusive="###" maxInclusive="###"></pa:TotalTerm>
<Class display="###" malid="###" longname="###">
<pa:FixedTerm value="###"></pa:FixedTerm>
</Class>
</Product>
<Product display="###" productcode="###" productname="###" longname="###">
<pa:TotalTerm minInclusive="###" maxInclusive="###"></pa:TotalTerm>
<pa:RepaymentType value="###"></pa:RepaymentType>
<pa:RepaymentType value="###"></pa:RepaymentType>
<pa:Feature name="###"></pa:Feature>`enter code here`
<pa:Feature name="###"></pa:Feature>
</Product>
</OldProducts>
<Products>
<pa:TotalAmount minInclusive="###"></pa:TotalAmount>
<Product display="###">
<Product display="###" productcode="###" productname="###" longname="###" discontinued="###" legacy="###">
<pa:TotalTerm minInclusive="###" maxInclusive="###"></pa:TotalTerm>
<pa:FixedTerm minInclusive="###" maxInclusive="###"></pa:FixedTerm>
<pa:Amount minInclusive="###"></pa:Amount>
<pa:RepaymentFrequency value="Weekly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Fortnightly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Monthly"></pa:RepaymentFrequency>
<Class display="###" productcode="###" malid="###" longname="###" PMPID="###" discontinued="###" legacy="###">
<pa:RepaymentFrequency value="Test-RepaymentFrequencyB"></pa:RepaymentFrequency>
<pa:FixedTerm value="###"></pa:FixedTerm>
<pa:Feature name="###"></pa:Feature>
<pa:LoanFeature value="###"></pa:LoanFeature>
<pa:RepaymentType value="###">
<pa:RepaymentFrequency value="Test-RepaymentFrequencyB"></pa:RepaymentFrequency>
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
<!-- Added to disable restrictions during testing -->
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
</pa:RepaymentType>
</Class>
</Product>
<Product display="###" productcode="###" productname="###" longname="###" malid="###" PMPID="###" value="###" discontinued="###" legacy="###">
<pa:TotalTerm minInclusive="###" maxInclusive="###"></pa:TotalTerm>
<pa:Amount minInclusive="###"></pa:Amount>
<pa:RepaymentFrequency value="Monthly"></pa:RepaymentFrequency>
<pa:RepaymentType value="###">
<pa:RepaymentFrequency value="Weekly"></pa:RepaymentFrequency>
<pa:RepaymentFrequency value="Fortnightly"></pa:RepaymentFrequency>
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
</pa:RepaymentType>
<pa:RepaymentType value="###">
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
<!-- Added to disable restrictions during testing -->
<pa:RepaymentMethod value="###"></pa:RepaymentMethod>
</pa:RepaymentType>
<pa:IOTerm minInclusive="###" maxInclusive="###"></pa:IOTerm>
</Product>
</Product>
</Products>
</Data>