我正在做一个项目,我需要有如下格式的空 xml 标签 <xyz></xyz>
而不是自闭标签 <xyz/>
,虽然两者相等,但客户端的实现似乎有问题。它接受空标签并拒绝自关闭标签。
我正在使用 WSO2 Integrator,但是它强制将所有空标签格式化为自关闭标签。有没有办法按照说明将其重新格式化为空标签?
最佳答案
尝试使用 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>
关于xml - 如何在 WSO2 Integration 上将自闭标签 xml 转换为空标签 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44996755/