2017-10-19 149 views
-1

当前头XSLT头问题

<Invoice xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:noNamespaceSchemaLocation="Factuur_insbou003.xsd"> 

新标题

<Invoice xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns="http://www.gs1.nl/factuur/insbou/004" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.gs1.nl/factuur/insbou/004 
          Factuur_insbou004.xsd"> 

我尝试这样做:

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

    <xsl:template match="/*[local-name()= 'Invoice']"> 
    <Invoice xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns="http://www.gs1.nl/factuur/insbou/004" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <xsl:copy-of select="node()|@*"/> 
    </Invoice> 
    </xsl:template> 


</xsl:stylesheet> 

你是正确的(删除了错误的代码),我的问题是创建的xmlns = “http://www.gs1.nl/factuur/insbou/004”。希望您能够帮助我。谢谢

+1

目前尚不清楚是什么问题... – Ray

+0

问题:我不能添加xmlns =“http://www.gs1.nl/factuur/insbou/004” – LDH

回答

0

您必须明白命名空间是文档中每个元素的限定名称的一部分,因此您需要更改每个元素的命名空间,例如,

<xsl:template match="*"> 
    <xsl:element name="{local-name()}"> 
    <xsl:apply-templates select="@* | node()"/> 
    </xsl:element> 
</xsl:template> 

然后在你的样式表根目录下,你可以简单地声明你想要的命名空间。但是当你还想要一个属性添加到根元素,而忽略另一个,你还需要一个模板,这样做,因此,所有的变化,你需要

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     version="1.0"  
     xmlns="http://www.gs1.nl/factuur/insbou/004" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 


    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="/Invoice"> 
     <Invoice 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xsi:schemaLocation="http://www.gs1.nl/factuur/insbou/004 
          Factuur_insbou004.xsd"> 
      <xsl:apply-templates/> 
     </Invoice> 
    </xsl:template> 

    <xsl:template match="*"> 
     <xsl:element name="{local-name()}"> 
     <xsl:apply-templates select="@* | node()"/> 
     </xsl:element> 
    </xsl:template> 

</xsl:transform>