简体   繁体   English

在根中添加命名空间会被复制到子节点

[英]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.在我在此站点上找到的以下示例中,一个空的xmlns=""被复制到所有子节点中。 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).如果没有查看所有代码,我们无法具体告诉您您做错了什么,但是当序列化程序发现结果树在 no namespace 中有一个元素,其父元素在一个命名空间中时,它会生成命名空间声明xmlns="" (但没有前缀)。

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.要找出为什么子元素不在命名空间中,而不是在与其父元素相同的命名空间中,您需要查看创建子元素的 XSLT 代码。 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).它永远不会从结果树中其父元素的命名空间自动继承(尽管它可能是从样式表中的父元素继承的)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WPF:Treeview Item Root使用不同的模板然后使用子节点 - WPF: Treeview Item Root uses different template then child nodes Java用替换复制xml节点和子节点 - Java duplicating xml node and child nodes with replace TemplateBuilder和SideWaffle。 项目模板。 更改默认的根名称空间 - TemplateBuilder and SideWaffle. Project template. Change default root namespace 具有附加属性的样式在根命名空间中有效,在嵌套命名空间中或由外部程序集访问时失败 - Style with Attached Properties Works In Root NameSpace, Fails in Nested Namespace or when accessed by external assembly 在父视图CakePHP中添加孩子 - Adding a Child in Parent View CakePHP XSLT-遍历XML以查找具有特定值的子节点 - XSLT - Looping through XML to find child nodes with a specific value xsl在我想要的位置下面的行上打印子节点 - xsl prints child nodes on the line below where I want it 为什么使用范围解析运算符更改全局命名空间中哪个重载模板被调用? - Why does using the scope resolution operator change which overloaded template in the global namespace gets called? 添加“ get_template_part”后内容将被替换 - Content gets replaced after adding “get_template_part” 我不明白在C ++ 14的[namespace.memdef] / 3中的示例中,模板函数如何成为类A :: X :: Y的朋友 - I don't understand how the template function gets to be a friend of the class A::X::Y in the example in [namespace.memdef]/3 in C++14
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM