Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT injects unwanted namespace in output file

I've seen similar questions, but it is still unclear to me. I don't want the "n1" namespace to appear in the attribute of the node in the output file. But I had to create the "n1" namespace in the xslt file in order to get xpath to work. Thank you.

XSLT:

   <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:n1="http://www.spicefactory.org/parsley"
        xmlns="http://www.spicefactory.org/parsley"
        >

    <xsl:output method="xml" indent="no"/>

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

     <xsl:template match="n1:object[@type='mytype1']">
      <object  type="mytype2">
        <xsl:apply-templates select="node()"/>
      </object>
     </xsl:template>

EXCERPT FROM OUTPUT XML FILE:

<object type="mytype2" xmlns:n1="http://www.spicefactory.org/parsley">
like image 423
dt1000 Avatar asked Feb 11 '11 20:02

dt1000


1 Answers

Use exclude-result-prefixes attribute on <xsl:stylesheet> element.

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:n1="http://www.spicefactory.org/parsley"
    xmlns="http://www.spicefactory.org/parsley"
    exclude-result-prefixes="n1"
    >
like image 188
jasso Avatar answered Sep 21 '22 22:09

jasso