如何使用xslt比较具有group by函数的元素与其他兄弟元素的值



我有以下xml -

<Invoices>
<Invoice>
<InvoiceNum>1234</InvoiceNum>
<BusinessNum>9999</BusinessNum>
</Invoice>
<Invoice>
<InvoiceNum>1234</InvoiceNum>
<BusinessNum>9999</BusinessNum>
</Invoice>
<Invoice>
<InvoiceNum>1235</InvoiceNum>
<BusinessNum>9998</BusinessNum>
</Invoice>
<Invoice>
<InvoiceNum>1235</InvoiceNum>
<BusinessNum>9990</BusinessNum>
</Invoice>
</Invoices>

首先,我必须根据Invoice num对这个XML进行分组,然后只有当InvoiceNum的节点的BusinessNum相同时,我才必须进行映射。对于ex - InvoiceNum, 1234是允许的,因为两个节点的BusinessNum相同,而1235是不允许的,因为两个节点的BusinessNum不同。

我试过下面的XSLT -

<xsl:for-each-group select="/Invoices" group-by="Invoice">
<xsl:if test="preceding-sibling::current-group()/BusinessNum[1] = BusinessNum">
</xsl:if>
// Further mapping

上面的XSLT映射不起作用。你能帮我用xslt 2.0做这个映射吗?

下面的xsl选择"allowed"通过检查每组BusinessNum的所有值都相同来确定InvoiceNums:

<xsl:template match="Invoices">
<xsl:for-each-group select="Invoice" group-by="InvoiceNum">
<xsl:if test="count(distinct-values(current-group()/BusinessNum))=1">
<xsl:value-of select="current-grouping-key()"/>                     
</xsl:if>
</xsl:for-each-group>
</xsl:template>

相关内容

  • 没有找到相关文章