Changing namespace for XML file in XSL Translation

前端 未结 1 939
忘掉有多难
忘掉有多难 2021-02-02 02:08

So I have an input file that uses my company\'s namespace in the default namespace (xmlns=\"companyURL\") but I want my output file to use something other than the

相关标签:
1条回答
  • 2021-02-02 02:22

    This transformation:

     <xsl:template match="*">
         <xsl:element name="cmp:{name()}" namespace="CompanyURL">
           <xsl:copy-of select="@*"/>
           <xsl:apply-templates/>
         </xsl:element>
     </xsl:template>
     <xsl:template match="/*">
         <cmp:container xmlns:cmp="CompanyURL">
           <xsl:copy-of select="@*"/>
           <xsl:apply-templates/>
         </cmp:container>
     </xsl:template>
    </xsl:stylesheet>
    

    when performed on the provided XML document:

    <foo xmlns="companyURL">
      <num1>asdf</num1>
      <num2>ghjkl</num2>
    </foo>
    

    produces the wanted, correct result:

    <cmp:container xmlns:cmp="CompanyURL">
       <cmp:num1>asdf</cmp:num1>
       <cmp:num2>ghjkl</cmp:num2>
    </cmp:container>
    
    0 讨论(0)
提交回复
热议问题