XSLT header 个问题

XSLT header problems

当前header

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

新建header

<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"。希望您能够帮助我。谢谢

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

<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>