gpt4 book ai didi

xslt - 没有命名空间的 XML

转载 作者:行者123 更新时间:2023-12-04 23:07:47 25 4
gpt4 key购买 nike

我需要从信封中提取 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 中是否具有命名空间声明应该无关紧要。

关于xslt - 没有命名空间的 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14367127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com