我需要从信封中提取
XML.但我无法得到我想要的输出.
我需要摆脱输出中的命名空间.
我需要摆脱输出中的命名空间.
我的意见:
<ns1:input xmlns:ns1="http://mysapmle.org/" xmlns="http://othersample.org/"> <sample> <inner tc="5">Test</inner> <routine>Always</routine> </sample> </ns1:input>
我的预期成果:
<sample> <inner tc="5">Test</inner> <routine>Always</routine> </sample>
我的实际产出:
<sample xmlns="http://othersample.org/"> <inner tc="5">Test</inner> <routine>Always</routine> </sample>
我的XSLT:
<xsl:output omit-xml-declaration="yes" indent="yes" /> <xsl:template match="/"> <xsl:copy copy-namespaces="no"> <xsl:apply-templates select="//sample" /> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy copy-namespaces="no"> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template>
请帮忙.
解决方法
这应该用于剥离命名空间:
<xsl:output omit-xml-declaration="yes" indent="yes" /> <xsl:template match="/"> <xsl:apply-templates select="*/*" /> </xsl:template> <xsl:template match="@*"> <xsl:attribute name="{local-name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> <xsl:template match="*"> <xsl:element name="{local-name()}"> <xsl:apply-templates select="@* | node()" /> </xsl:element> </xsl:template>
但我有点怀疑你需要这样做.如果您要将此附加到的XML使用相同的命名空间,并且这是包含XML的命名空间应该具有的,那么此XML中的命名空间声明应该无关紧要.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。