3

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>


Sample 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>


Resulting XML:

<tag1>
  <tag1_1>text</tag1_1>

  <tag1_3>
    <tag1_3_1 />

  </tag1_3>
</tag1>
0

1 Answer 1

6

You could use xsl:strip-space:

<xsl:strip-space elements="*"/> 
1
  • Very useful tip! This goes into my personal arsenal. Commented Dec 14, 2009 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.