XSLT: how to prevent XSLT code from creating excess space in the xml output file

With my XSL code, whenever I delete an item. It will enter a blank space-space in the output xml .. file, which interferes with the structure of the XML tree structure . Can you please suggest me .. How to get rid of it ..?

Here are sample code samples.

XML example:

<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 Example:

<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 Result:

<tag1>
  <tag1_1>text</tag1_1>

  <tag1_3>
    <tag1_3_1 />

  </tag1_3>
</tag1>
+3
source share
1 answer

You can use xsl: strip-space :

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

Source: https://habr.com/ru/post/1725594/


All Articles