删除重命名元素的命名空间 [英] Remove namespace for the renamed element

查看:74
本文介绍了删除重命名元素的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在使用XSLT 1.0进行转换后删除输出中的元素的命名空间。



我有什么:



我有一个输入XML,其中一个元素架构已更改。因此,根据新架构,我重命名了它。现在对于那个特定的元素,我在输出XML中得到一个额外的命名空间。



不知何故,我正在使用的XSL正在删除xml中的所有命名空间,如soap信封,肥皂体等,不仅仅用于修改过的元素。



为什么只有更改的元素才会给出命名空间错误。对此有任何建议都是受欢迎的。如何删除元素重命名后的命名空间。



I am trying to remove namespaces for an element coming in my output after going through transformation using XSLT 1.0.

What I had:

I am having a input XML, in which one elements schema got changed. So as per the new schema, I renamed it. Now for that particular element, I am getting an extra namespace in the output XML.

Somehow, the XSL I am using is removing all the namespaces in xml like soap envelope, soap body etc, not only for the modified element.

Why only the changed element is giving namespace error. Any suggestions on this are welcome. How to remove the namespace coming after the element renamed.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope>
<xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<MyRequest>
<Details>
<ID>123</ID>
<Name>
<FirstName>John</FirstName>
</Name>
</Details>
</MyRequest>
</soapenv:Body>
</soapenv:Envelope>







使用XSL






XSL used

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"             version="1.0"

xmlsns:ns = "www.newschema"

exclude-element-prefix = "xsl ns">
<xsl:template match="Details" ns=www.Newschema>
<PartyDetails ns=www.Newschema>
<xsl:apply-templates select="node()"/>
</PartyDetails

</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="comment() | processing-instruction()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>







我想要的输出。






Output I want.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope(xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/")>
<soapenv:Body>
<MyRequest>
<PartyDetails>
<ID>123</ID>
<Name>
<FirstName>John</FirstName>
</Name>
</PartyDetails>
</MyRequest>
</soapenv:Body>
</soapenv:Envelope>

推荐答案

Can you please try with ns="www.Newschema" in PartyDetails element or &lt;ns:partydetails&gt; and let me know 


这篇关于删除重命名元素的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆