2013-11-28 77 views
0

我試圖從外部xsd文件中檢索類型定義。在這個例子中,我的$attType有一個名稱空間前綴。但是在XPath中,我使用它來獲取不需要前綴的定義。 現在的問題是:如何?使用xslt刪除名稱空間前綴

<xsl:copy-of select="document('../file.xsd')//xs:simpleType[@name=$attType]" /> 
+0

參見http://stackoverflow.com/questions/9304592/xslt-how-get-rid-of-default -namespaces-prefixes-in-xpath-xmlns – halfbit

+1

我採取了骯髒的解決方案:substring-after($ attType,':') – cRiMi

回答

0

稍微不太髒的解決方案是使用local-name()來正確確定名稱空間內對象的名稱。

這應剝去元件和attirbutes命名空間,並保留文本:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="@*"> 
    <xsl:attribute name="{local-name(.)}"> 
     <xsl:value-of select="." /> 
    </xsl:attribute> 
    </xsl:template> 
    <xsl:template match="node()"> 
    <xsl:element name="{local-name(.)}"> 
     <xsl:apply-templates select="@*|*|text()"/> 
    </xsl:element> 
    </xsl:template> 
    <xsl:template match="text()"> 
     <xsl:copy /> 
    </xsl:template> 
</xsl:stylesheet>