简体   繁体   中英

Adding namespace in root gets copied to child nodes

In below example which I found on this site, an empty xmlns="" gets copied in all child nodes. What can the reason be for this mistake?

My Template:

     <xsl:element xmlns="http://www.element-examples.org" name="{local-name()}">
       <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
 </xsl:template>  

OUTPUT:

    <projectgegevens xmlns="http://www.element-examples.org">
      <idopdracht **xmlns=""**>28062262</idopdracht>
      <projectcode **xmlns=""**>160622</projectcode>
      <projectnaam **xmlns=""**>FF0000390001</projectnaam>
      <ordernummer xmlns="">M2M-2022010071</ordernummer>
      <projectleider xmlns="">FF000039003</projectleider>
      <opmerking xmlns=""></opmerking>
      <status xmlns="">5</status>
      <datumverwacht xmlns="">2022-06-29</datumverwacht>
      <certificaatnummer xmlns="">2020083810</certificaatnummer>
      <analysemonsters xmlns="">

We can't tell you specifically what you did wrong without seeing all your code, but the namespace declaration xmlns="" is generated by the serializer when it finds that the result tree has an element in no namespace, whose parent is in a namespace (but with no prefix).

To find out why the child elements are in no namespace, rather than in the same namespace as their parent, you need to look at the XSLT code that creates the child elements. Note that the namespace of an element is determined entirely by the instruction that creates the element; it is never inherited automatically from the namespace of its parent element in the result tree (though it may be inherited from the parent element in the stylesheet).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM