我试图从一个属性值=0(数量)的xml中“剥离”节点。
我的输入xml是:
<?xml version="1.0" encoding="utf-16"?>
<StockAdjustments xmlns="http://example.com/IWS/StockAdjustments">
<StockAdjustment Article="VL04604" Client="BHP" Status="PAXD" Unit="M2" Quantity="-96" ReasonCode="TELVERSCHI" Batch="VK00427062" HostLocation="BHP" />
<StockAdjustment Article="VL04604" Client="BHP" Status="" Unit="M2" Quantity="0" ReasonCode="TELVERSCHI" Batch="VK00427062" HostLocation="BHP" />
</StockAdjustments>
所要求/预期的结果是:
<?xml version="1.0" encoding="utf-16"?>
<StockAdjustments xmlns="http://example.com/IWS/StockAdjustments">
<StockAdjustment Article="VL04604" Client="BHP" Status="PAXD" Unit="M2" Quantity="-96" ReasonCode="TELVERSCHI" Batch="VK00427062" HostLocation="BHP" />
</StockAdjustments>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:iws="http://example.com/IWS/StockAdjustments"
xmlns="http://example.com/IWS/StockAdjustments"
excluxxde-result-prefixes="iws">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/iws:StockAdjustments/iws:StockAdjustment[@Quantity != '0']">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这让我
<?xml version="1.0" encoding="UTF-8"?>
<StockAdjustment xmlns="http://example.com/IWS/StockAdjustments">VL04604BHPPAXDM2-96TELVERSCHIVK00427062BHP</StockAdjustment>
我感觉我就快到了,我需要什么来获得所需的输出?
迈克
[使用解决方案更新]
感谢Michael,这是解决我“问题”的正确xslt
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:iws="http://example.com/IWS/StockAdjustments">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/iws:StockAdjustments">
<xsl:copy>
<xsl:copy-of select="iws:StockAdjustment[@Quantity != 0]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>