2014-11-03 24 views
0

我是XSLT新手,我有特殊要求。我的XML文件如下所示。如何修剪XSLT使用屬性表達式

<results> 
    <result> 
    <Price> 
     <LinePrices> 
     <ProductId>ProductId:1000</ProductId> 
     <Uom>KG</Uom> 
     <Quantity>0</Quantity> 
     </LinePrices> 

     <LinePrices> 
     <ProductId>ProductId:1002</ProductId> 
     <Uom>EACH</Uom> 
     <Quantity>0</Quantity> 
     </LinePrices> 
    </Price> 
    </result> 

    <result> 
    <productlist> 
     <productid>1000</productid> 
     <relevance>0.9</relevance> 
     <sponsored>0</sponsored> 
    </productlist> 
    <productlist> 
     <productid>1001</productid> 
     <relevance>0.8</relevance> 
     <sponsored>0</sponsored> 
    </productlist> 
    </result> 
</results> 

我必須編寫XSLT鍵來匹配模式。我已經寫下了產品列表的關鍵字,如下所示。

<xsl:key name="productsIdForProduct" match="productlist" use="productid" /> 

以類似的方式,我試圖爲LinePrices編寫密鑰,如下所示。

<xsl:key name="productsIdPrice" match="result/LinePrices" use="ProductId" /> 

但是,這返回使用屬性中的'ProductId:1000'。我試圖從use屬性值中修剪'ProductId:'。我如何編寫一個修剪表達式來在XPATH表達式中從'ProductId:1000'中提取'1000'?

回答

2

只需使用子串()之後:

substring-after(ProductId,':') 
+0

謝謝。這工作非常好 – user3796454 2014-11-04 01:35:20