2011-08-31 67 views
1
<Product xmlns:fish="urn:fish.com:international"> 
     <Assets fish:relativePath="013\7614500010013"> 
     </Assets> 
</Product> 

我需要能夠獲取asset屬性fish:relativePath和xslt。我該怎麼做呢?使用命名空間和xslt獲取屬性值

我已經把魚名稱空間放入xslt頭文件中。

 <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:asp="remove" 
xmlns:fish="urn:fish.com:international"> 

在此先感謝。

回答

3

創建訪問使用@屬性的資產節點模板,然後將其應用:

<xsl:stylesheet version="1.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:asp="remove" 
       xmlns:fish="urn:fish.com:international"> 

    <xsl:template match="/"> 
    <xsl:apply-templates select="/Product/Assets"/> 
    </xsl:template> 

    <xsl:template match="Assets"> 
    <xsl:value-of select="@fish:relativePath"/> 
    </xsl:template> 

</xsl:stylesheet>