3

我正在做一个项目,我需要将空 xml 标签格式化为如下格式,<xyz></xyz>而不是自动关闭标签<xyz/>,尽管两者都是相等的,但似乎客户端的实现是错误的。它接受空标签并拒绝自闭合标签。

我正在使用 WSO2 Integrator,但是它强制将所有空标签格式化为自闭合标签。有没有办法按照解释将其重新格式化为空标签?

4

1 回答 1

0

尝试使用 XSLT 中介。这些可能会起作用。

<!-- Define a dummy variable with empty content -->
<xsl:variable name="empty" select="''"/>

<!-- Copy input to output, most of the time -->
<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()" />
<!-- Insert empty content into copied element -->
        <xsl:value-of select="$empty"/>
    </xsl:copy>
</xsl:template>

或者

<!-- Identity template for empty elements -->
<xsl:template match="*[not(node())]">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()" />
        <xsl:value-of select="$empty"/>
    </xsl:copy>
</xsl:template>

参考:https ://stackoverflow.com/a/5033301/805563

于 2017-07-18T18:40:30.570 回答