xsl-list
[Top] [All Lists]

[xsl] Storing output tree in a variable and stripping

2010-10-19 14:15:40
Hello,

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"/>
 ...
</xsl:variable>

... 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="."/>
</xsl:for-each>

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




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--