[xsl] Storing output tree in a variable and stripping

Subject: [xsl] Storing output tree in a variable and stripping
From: hallo@xxxxxxxxxxxxx
Date: Tue, 19 Oct 2010 21:15:17 +0200

I just investigated the possibility to store the output tree in a variable ...

<xsl:variable name="outputRaw">
 <xsl:apply-templates match="abc"/>
 <xsl:apply-templates match="def"/>

... in order to strip away all empty elements without having (a) to create a separate stylesheet which would do this job or (b) complex if-then structures in order to prevent the creation of an empty element beforehand.

Below is the xslt-code which is responsible for selecting and displaying only non-empty nodes which had been created beforehand by the given templates and stored in the $outputRaw variable.

<xsl:for-each select="$outputRaw/*[text() | *]">
 <xsl:copy-of select="."/>

Although this solution seems to me pretty elegant in comparison to (a) a separate stylesheet or (b) if-then structures which would only bloat the xslt-code , I'm not quite sure if this solution is a good idea regarding the performance of the stylesheet.

I would be very thankful for any clues and advice.

Regards, Matthias

Current Thread