我試圖將一對XML文件中的子項複製到另一個XML文件中。我創建了一個適用於指定元素的白名單,但當我嘗試限制同時也是子項的單個屬性名稱值對時,我找不到匹配項。XSLT複製受限於屬性值對
示例XML:
<?xml version="1.0" encoding="UTF-8"?>
<catalog catalog-id="Primary">
<product product-id="COLAKIT">
<ean/>
<upc/>
<unit>SKU</unit>
<custom-attributes>
<custom-attribute attribute-id="Base_Color">Brown</custom-attribute>
<custom-attribute attribute-id="Shipping_Cost">0.0</custom-attribute>
<custom-attribute attribute-id="showEstimatedDelivery">false</custom-attribute>
</custom-attributes>
<classification-category>Kitchen_Housewares-Coffee_and_Tea</classification-category>
</product>
<product product-id="COLONIAL-48-M-K">
<ean/>
<upc/>
<unit>SKU</unit>
<custom-attributes>
<custom-attribute attribute-id="Base_Color">Coffee</custom-attribute>
<custom-attribute attribute-id="Shipping_Cost">0.0</custom-attribute>
<custom-attribute attribute-id="showEstimatedDelivery">false</custom-attribute>
</custom-attributes>
<classification-category>Outdoor_Living-Heaters-Fireplaces</classification-category>
</product>
</catalog>
XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="some:ns">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<ns:WhiteList>
<name>classification-category</name>
<name>custom-attribute[attribute-id()='Shipping_Cost']</name>
</ns:WhiteList>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(descendant-or-self::*[name()=document('')/*/ns:WhiteList/*])]"/>
</xsl:stylesheet>
此外,主XML具有節點的100S,我只想要3這是爲什麼我想白名單,而不是排斥。請讓我知道我缺少的屬性=值匹配。
謝謝。這很好。我很感激幫助。對字符串XPath有意義 – Curtis 2014-09-30 15:19:47