我已經搜索,但我找不到適當的解決方案來處理xslt 1.0中的名稱空間。每個節點都有很多屬性,但爲了便於閱讀,我沒有給出它們。從源xml替換名稱空間
我的輸入XML
<?xml version="1.0" encoding="UTF-8"?>
<Vendor VendorId="v1" VendorName="vaseline health" xmlns:ns1="http://ABCSampleDemo.SampleDemo" >
<Customer CustId="c1" CustomerName="John Dillon" CustomerAddress="3093 jerfe st" Code="APL111">
<POrders PId="P0110" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T000" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
<POrders PId="P0111" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T000" PurchaseStart="09-09-2012" PurchaseEnd="10-10-2011" WarehouseId="W2013" />
<ID AuthId= "1111"/>
<POrders PId="P0112" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T000" PurchaseStart="09-09-2012" PurchaseEnd="10-10-2011" WarehouseId="W2013" />
<ID AuthId= "1111"/>
<POrders PId="P0113" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T001" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
<POrders PId="P0114" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T001" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
<POrders PId="P0115" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T001" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
<POrders PId="P0116" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T001" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
<POrders PId="P0117" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T001" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
<POrders PId="P0118" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T001" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
</Customer>
<Customer CustId="C2" CustomerName="Mac Payne" CustomerAddress="3333 jerfe st" Code="APL113">
<POrders PId="P2221" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T000" PurchaseStart="01-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
<POrders PId="P2222" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T000" PurchaseStart="01-09-2012" PurchaseEnd="10-10-2011" WarehouseId="W2013" />
<ID AuthId= "1111"/>
<POrders PId="P2223" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T000" PurchaseStart="01-09-2012" PurchaseEnd="10-10-2011" WarehouseId="W2013" />
<ID AuthId= "1111"/>
<POrders PId="P2224" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T001" PurchaseStart="01-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
<POrders PId="P2225" PName="uuu aillw" Units="3" Amount="100" ServiceRef="T001" PurchaseStart="01-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" />
<ID AuthId= "1111"/>
</Customer>
</Vendor>
CURRENT SS,
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name=" KPOrderAttrb" use="concat(@ServiceRef,'+',@WarehouseId,'+',substring(@PurchaseStart,1,10))" match="POrders"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each select="Customer">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="ClientSeqNo"><xsl:number count="Customer"/></xsl:attribute>
<xsl:for-each select="descendant::POrders[generate-id() = generate-id(key('KPOrderAttrb', concat(@ServiceRef,'+',@WarehouseId,'+',substring(@PurchaseStart,1,10))) [1])]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:variable name="vGroup" select="key('KPOrderAttrb',concat(@ServiceRef,'+',@WarehouseId,'+',substring(@PurchaseStart,1,10)))"/>
<xsl:variable name="vPOrderIds">
<xsl:for-each select="$vGroup">
<xsl:sort select="@PId" data-type="number"/>
<xsl:if test="not(position()=1)">
<xsl:value-of select="','"/>
</xsl:if>
<xsl:value-of select="@PId"/>
</xsl:for-each>
</xsl:variable>
<xsl:attribute name="index"><xsl:value-of select="position()"/></xsl:attribute>
<xsl:attribute name="Code"><xsl:value-of select="ancestor::Customer[1]/@Code"/></xsl:attribute>
<xsl:attribute name="AuthId"><xsl:value-of select="descendant::ID[1]/@AuthId"/></xsl:attribute>
<xsl:attribute name="CombinePOID"><xsl:value-of select="$vPOrderIds"/></xsl:attribute>
<xsl:attribute name="Amount"><xsl:value-of select="sum($vGroup/@Amount)"/></xsl:attribute>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
期望的輸出XML
<Vendor xmlns:ns1="http://xyzDemo.xyzDemo" VendorId="v1" VendorName="vaseline health">
<Customer CustId="c1" CustomerName="John Dillon" CustomerAddress="3093 jerfe st" Code="APL111" ClientSeqNo="1">
<POrders PId="P0110" PName="uuu aillw" Units="3" ServiceRef="T000" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" index="1" Code="APL111" AuthId="" CombinePOID="P0110" Amount="100"/>
<POrders PId="P0111" PName="uuu aillw" Units="3" ServiceRef="T000" PurchaseStart="09-09-2012" PurchaseEnd="10-10-2011" WarehouseId="W2013" index="2" Code="APL111" AuthId="" CombinePOID="P0111,P0112" Amount="200"/>
<POrders PId="P0113" PName="uuu aillw" Units="3" ServiceRef="T001" PurchaseStart="09-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" index="3" Code="APL111" AuthId="" CombinePOID="P0113,P0114,P0115,P0116,P0117,P0118" Amount="600"/>
</Customer>
<Customer CustId="C2" CustomerName="Mac Payne" CustomerAddress="3333 jerfe st" Code="APL113" ClientSeqNo="2">
<POrders PId="P2221" PName="uuu aillw" Units="3" ServiceRef="T000" PurchaseStart="01-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" index="1" Code="APL113" AuthId="" CombinePOID="P2221" Amount="100"/>
<POrders PId="P2222" PName="uuu aillw" Units="3" ServiceRef="T000" PurchaseStart="01-09-2012" PurchaseEnd="10-10-2011" WarehouseId="W2013" index="2" Code="APL113" AuthId="" CombinePOID="P2222,P2223" Amount="200"/>
<POrders PId="P2224" PName="uuu aillw" Units="3" ServiceRef="T001" PurchaseStart="01-09-2011" PurchaseEnd="10-10-2011" WarehouseId="W2023" index="3" Code="APL113" AuthId="" CombinePOID="P2224,P2225" Amount="200"/>
</Customer>
</Vendor>
首先,您需要格式化您的代碼,使其至少可見(更好:甚至可讀。選擇代碼並單擊「{}」按鈕。即使在此之後,您還需要添加一個口頭描述如果你不提供這些信息,那麼一個有效的解決方案就是將你想要的輸出複製到一個無關緊要的無意義的XSLT轉換中,請改進這很難理解文本 – 2011-05-04 03:53:25
@Dimitre:按照要求我已經更新了實際的輸入,輸出和當前使用的xsl,我認爲刪除所有這些屬性對於可讀性會有幫助。謝謝。是否有可能進行上述轉換。 – bluesnowxyz 2011-05-05 00:11:47