我想编写一个XSLT,我可以在翻译时删除重复的节点。在下面的消息中,由于 1 和 3 节点的温度代码相同,因此对我来说是重复的。
我正在使用的示例输入消息是
<document>
<party>
<gtin>1000909090</gtin>
<pos>
<attrGroupMany name="temperatureInformation">
<row>
<attr name="temperatureCode">STORADE</attr>
<attrQual name="maximumTemperature" qual="FAH">80</attrQual>
<attrQual name="minimumTemperature" qual="ABC">10</attrQual>
</row>
<row>
<attr name="temperatureCode">HANDLING</attr>
<attrQual name="maximumTemperature" qual="XYZ">20</attrQual>
<attrQual name="minimumTemperature" qual="PQR">30</attrQual>
</row>
<row>
<attr name="temperatureCode">STORADE</attr>
<attrQual name="maximumTemperature" qual="FAH">80</attrQual>
<attrQual name="minimumTemperature" qual="ABC">10</attrQual>
</row>
</attrGroupMany>
</pos>
</party>
</document>
我正在使用下面的 XSLT 来转换示例消息
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="document">
<CatalogItem>
<RelationshipData>
<Relationship>
<RelationType>temperatureInformation_details</RelationType>
<RelatedItems>
<xsl:for-each select="party/pos/attrGroupMany[@name ='temperatureInformation']/row">
<RelatedItem>
<xsl:attribute name="referenceKey">
<xsl:value-of select="concat('temperatureInformation_details','-',attr[@name='temperatureCode'],'-',attrQual/@name,'-',attrQual/@qual,'-',attrQual )"/>
</xsl:attribute>
</RelatedItem>
</xsl:for-each>
</RelatedItems>
</Relationship>
</RelationshipData>
</CatalogItem>
</xsl:template>
</xsl:stylesheet>
但是当前输出不正确,它具有重复的STORADE值
<?xml version="1.0" encoding="UTF-8"?>
<CatalogItem>
<RelationshipData>
<Relationship>
<RelationType>temperatureInformation_details</RelationType>
<RelatedItems>
<RelatedItem referenceKey="temperatureInformation_details-STORADE-maximumTemperature-FAH-80" />
<RelatedItem referenceKey="temperatureInformation_details-HANDLING-maximumTemperature-XYZ-20" />
<RelatedItem referenceKey="temperatureInformation_details-STORADE-maximumTemperature-FAH-80" />
</RelatedItems>
</Relationship>
</RelationshipData>
</CatalogItem>
正确的输出应如下所示,其中删除了重复的温和代码。
<?xml version="1.0" encoding="UTF-8"?>
<CatalogItem>
<RelationshipData>
<Relationship>
<RelationType>temperatureInformation_details</RelationType>
<RelatedItems>
<RelatedItem referenceKey="temperatureInformation_details-STORADE-maximumTemperature-FAH-80" />
<RelatedItem referenceKey="temperatureInformation_details-HANDLING-maximumTemperature-XYZ-20" />
</RelatedItems>
</Relationship>
</RelationshipData>
</CatalogItem>
任何输入都将非常有帮助
使用 Muenchian 分组来识别重复项,一个键可以是
<xsl:key name="group" match="row" use="concat(attr[@name = 'temperatureCode'], '-', attrQual[@qual = 'FAH'])"/>
然后更改
<xsl:for-each select="party/pos/attrGroupMany[@name ='temperatureInformation']/row">
自
<xsl:for-each select="party/pos/attrGroupMany[@name ='temperatureInformation']/row[generate-id() = generate-id(key('group', concat(attr[@name = 'temperatureCode'], '-', attrQual[@qual = 'FAH']))[1])]">