XSLT:如何防止 XSLT 代码在输出 xml 中生成冗余空格 [英] XSLT: how to prevent the XSLT code from generating redundant blank-space in output xml

查看:30
本文介绍了XSLT:如何防止 XSLT 代码在输出 xml 中生成冗余空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我的 XSL 代码,每当我删除一个元素 .. 它会在输出 xml 中引入一个空白行空间 .. 这会妨碍 XML 的 树结构外观 .. 你能吗?请建议我..如何摆脱它..?

这里是示例代码..

示例 XML:

With my XSL code, whenever I delete an element .. It will introduce a blank-line-space in output xml .. which hampers the Tree-structure look of the XML .. Can you please suggest me .. How to get rid of it .. ?

Here are sample the sample codes ..

Sample XML:

<tag1>
  <tag1_1>text</tag1_1>
  <tag1_2 delete="Y">text</tag1_2>
  <tag1_3>
    <tag1_3_1></tag1_3_1>
    <tag1_3_2 delete="Y">
      <tag_child>text</tag_child>
    </tag1_3_2>
  </tag1_3>
</tag1>


示例 XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
  <xsl:template match="//*[@delete='Y']"/>
</xsl:stylesheet>


结果 XML:

<tag1>
  <tag1_1>text</tag1_1>

  <tag1_3>
    <tag1_3_1 />

  </tag1_3>
</tag1>

推荐答案

你可以使用 xsl:strip-space:

<xsl:strip-space elements="*"/> 

这篇关于XSLT:如何防止 XSLT 代码在输出 xml 中生成冗余空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆