我需要在 xml 一个标签的属性中删除。 为此,我找到了使用 xslt 的解决方案:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:apply-templates select="node()|@*" />
</xsl:attribute>
</xsl:template>
它运行良好,甚至太多了,因为在删除过程之后,必要的属性变得没有前缀,但也没有内容。由于某种原因,前缀和内容都被截断,只剩下一个空属性,例如,应删除前缀的 attr "xsi:type":
<out:Declarant xsi:type="out:RequestAccount">
意料之中的是:
<out:Declarant type="out:RequestAccount">
但得到了这个:
<out:Declarant type="">
我不明白为什么删除"类型"的内容?
这是我的 XSD 文件到 XMLS 的地方: XSD 图像
type
的内容被删除,因为<xsl:apply-templates select="node()|@*" />
选择当前属性的子节点(和属性(,但属性不像元素那样具有子节点(或属性(。
相反,只需执行此操作...
<xsl:value-of select="." />