我的xml有点问题。如果LineItem下还有更多的文章(行),则第1条和第2条上应该有相同的文本。(重复检查应该在每行上-不在LineItem上)在线检查重复项应该是只需检查一下,如果LineItem上没有重复项。希望你能帮我?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
<xsl:key name="header_text" match="HeaderText" use="Text"/>
<xsl:key name="line_text" match="LineText" use="Text"/>
<!-- Identity-Template für die nicht explizit benannten Elemente -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="HeaderText[generate-id() != generate-id(key('header_text', Text)[1])]" />
<xsl:template match="LineText[generate-id() != generate-id(key('line_text', Text)[1])]" />
<!-- delete empty nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
</xsl:stylesheet>
像这样:
...<LineItem>
<Lines>
<OrderLineNum>1</OrderLineNum>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity>3</Quantity>
<PriceUnit>1</PriceUnit>
<FixedPrice>0</FixedPrice>
<SalesPrice>10</SalesPrice>
<DiscAmount>0</DiscAmount>
<DiscPercent>0</DiscPercent>
<SalesLinePercent1>0</SalesLinePercent1>
<SalesLinePercent2>0</SalesLinePercent2>
<MultiLnDisc>0</MultiLnDisc>
<MultiLnPercent>0</MultiLnPercent>
<LineAmount>0</LineAmount>
<SumLineDisc>0</SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount>0</VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
<LineText>
<Qualifier>LIN</Qualifier>
<Text>test</Text>
</LineText>
<LineText>
<Qualifier>DEL</Qualifier>
<Text>test 2</Text>
</LineText>
</Lines>
<Lines>
<OrderLineNum>2</OrderLineNum>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity>3</Quantity>
<PriceUnit>1</PriceUnit>
<FixedPrice>0</FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount>0</DiscAmount>
<DiscPercent>0</DiscPercent>
<SalesLinePercent1>0</SalesLinePercent1>
<SalesLinePercent2>0</SalesLinePercent2>
<MultiLnDisc>0</MultiLnDisc>
<MultiLnPercent>0</MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc>0</SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
<LineText>
<Qualifier>LIN</Qualifier>
<Text>test</Text>
</LineText>
<LineText>
<Qualifier>DEL</Qualifier>
<Text>test 2</Text>
</LineText>
</Lines>
</LineItem>
<Totals>...
第1行错误:
...<LineItem>
<Lines>
<OrderLineNum>1</OrderLineNum>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity>3</Quantity>
<PriceUnit>1</PriceUnit>
<FixedPrice>0</FixedPrice>
<SalesPrice>10</SalesPrice>
<DiscAmount>0</DiscAmount>
<DiscPercent>0</DiscPercent>
<SalesLinePercent1>0</SalesLinePercent1>
<SalesLinePercent2>0</SalesLinePercent2>
<MultiLnDisc>0</MultiLnDisc>
<MultiLnPercent>0</MultiLnPercent>
<LineAmount>0</LineAmount>
<SumLineDisc>0</SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount>0</VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
<LineText>
<Qualifier>LIN</Qualifier>
<Text>test</Text>
</LineText>
<LineText>
<Qualifier>DEL</Qualifier>
<Text>test 2</Text>
</LineText>
<LineText>
<Qualifier>LIN</Qualifier>
<Text>test</Text>
</LineText>
<LineText>
<Qualifier>DEL</Qualifier>
<Text>test 2</Text>
</LineText>
</Lines>
<Lines>
<OrderLineNum>2</OrderLineNum>
<GTIN></GTIN>
<GTINDescription></GTINDescription>
<SupplierArticleNumber></SupplierArticleNumber>
<Quantity>3</Quantity>
<PriceUnit>1</PriceUnit>
<FixedPrice>0</FixedPrice>
<SalesPrice></SalesPrice>
<DiscAmount>0</DiscAmount>
<DiscPercent>0</DiscPercent>
<SalesLinePercent1>0</SalesLinePercent1>
<SalesLinePercent2>0</SalesLinePercent2>
<MultiLnDisc>0</MultiLnDisc>
<MultiLnPercent>0</MultiLnPercent>
<LineAmount></LineAmount>
<SumLineDisc>0</SumLineDisc>
<DeliveredQuantity></DeliveredQuantity>
<VatBaseAmount></VatBaseAmount>
<VatPercentage></VatPercentage>
<Measure_Unit></Measure_Unit>
<LineText>
<Qualifier>LIN</Qualifier>
<Text>test</Text>
</LineText>
<LineText>
<Qualifier>DEL</Qualifier>
<Text>test 2</Text>
</LineText>
</Lines>
</LineItem>
<Totals>...
答案 0 :(得分:1)
我认为您需要密钥OrderLineNum
中的Lines
和Text
<xsl:key name="line_text" match="LineText" use="concat(../OrderLineNum, '|', Text)"/>
然后火柴变成这个...
<xsl:template match="LineText[generate-id() != generate-id(key('line_text', concat(../OrderLineNum, '|', Text))[1])]" />
尝试使用此XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
<xsl:strip-space elements="*" />
<xsl:key name="header_text" match="HeaderText" use="Text"/>
<xsl:key name="line_text" match="LineText" use="concat(../OrderLineNum, '|', Text)"/>
<!-- Identity-Template für die nicht explizit benannten Elemente -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="HeaderText[generate-id() != generate-id(key('header_text', Text)[1])]" />
<xsl:template match="LineText[generate-id() != generate-id(key('line_text', concat(../OrderLineNum, '|', Text))[1])]" />
<!-- delete empty nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
</xsl:stylesheet>