XSLT:将 <element></element> 转换为 <element/>

标签 xslt

我需要做什么:

    <xsl:template match="xs:simpleType">
      <xsl:copy>
        <xsl:copy-of select="node()[not(self::xs:annotation or self::xs:restriction)]|@*"/>
      </xsl:copy>
    </xsl:template>

目前,事实证明:

<xs:simpleType xmlns:core="urn:org:pesc:core:CoreMain:v1.4.0" name="SINIDType">


</xs:simpleType>

我希望它看起来像:

<xs:simpleType name="SINIDType" />

最佳答案

有了这些空行,看起来您的 select 语句(正确地)选择了空白节点以及元素。尝试使用

select="*[not(self::xs:annotation or self::xs:restriction)]|@*"

它只匹配元素节点,而不匹配文本节点。

关于XSLT:将 <element></element> 转换为 <element/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1101817/

相关文章:

java - 对 xslt 使用不同的编码

string - 如何将 xslt 模板应用于字符串?

css - 在xslt中获取循环内迭代元素的属性

xslt 1.0,字符串长度函数

xml - 使用 XSLT 2.0 读取文本文件时如何添加父元素?

xml - xsl :param namespace error (may not be used in namespace)

xml - XSLT将线性结构转换为非线性

xml - XSL 如果 : test with multiple test conditions

xml - 从单个 xslt 获取多个 xml 文档

xml - 需要更换命名空间