2013-02-11 81 views
0

我想用xslt轉換下面的xml。 注:我使用的名稱spave在輸入XMLXSLT2.0名稱空間支持

輸入XML

<?xml version="1.0" encoding="UTF-8"?> 
<Roottag xmlns="aaa"> 
    <Employee> 
     <name>Nimal</name> 
    </Employee> 
    <Employee> 
     <name>Kamal</name> 
    </Employee> 
    <Employee> 
     <name>Sunil</name> 
    </Employee> 
</Roottag> 

XSLT

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="//name"> 
     <xsl:element name="person"> 
      <xsl:value-of select="." /> 
     </xsl:element> 
    </xsl:template> 
</xsl:stylesheet> 

預計輸出

<?xml version="1.0" encoding="UTF-8"?> 

<person>Nimal</person> 
<person>Kamal</person> 
<person>Sunil</person> 

電流輸出

<?xml version="1.0" encoding="UTF-8"?> 
     Nimal 
     Kamal 
     Sunil 

任何一個可以請幫我解決xslt2.0改造這個名字空間的問題?

回答

1

隨着XSLT 2.0和XSLT 2.0處理器可以使用

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xpath-default-namespace="aaa"> 

    <xsl:template match="name"> 
     <person> 
      <xsl:value-of select="." /> 
     </person> 
    </xsl:template> 
</xsl:stylesheet> 

隨着XSLT 1.0處理器需要

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:df="aaa" exclude-result-prefixes="aaa"> 

    <xsl:template match="df:name"> 
     <person> 
      <xsl:value-of select="." /> 
     </person> 
    </xsl:template> 
</xsl:stylesheet> 
+0

感謝。這工作正常。 – user1586908 2013-02-11 11:06:20