RE: simulating conditional <xsl:include> behavior?

Subject: RE: simulating conditional <xsl:include> behavior?
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Wed, 3 Nov 1999 10:17:19 -0000
> What I would like to do is the equivalent of wrapping 
> <xsl:include> in an <xsl:if> or <xsl:for-each>. I want to pull into my
stylesheet 
> certain XSLT templates only when certain conditions are true -- namely, 
> the presence of certain data in a source document. 

This is going to be tricky, because generally the stylesheet will be read
and analysed before the source document is read (e.g. the processor will
generally read the xsl:strip-space and xsl:preserve-space elements before it
builds the source document tree; certainly it needs to read them before
evaluating any XPath expressions, because they can affect the result).

One thing you could try is to use external entity references in the
stylesheet instead of <xsl:include> (or perhaps in conjunction with
xsl:include). You could filter the SAX event stream used by the XSL
processor to read the stylesheet, and your filter could resolve the external
entity references based on any information it has to hand, including, if you
can afford the performance hit, reading the source document.

In SAXON, if you're not scared of getting into the guts, you could define an
extension element my:include, make the implementation class that supports it
a subclass of the one that supports xsl:include, and thus again use your own
logic to decide whether or not to invoke the superclass behaviour. But it
still wouldn't have access to the source document at this stage of
processing.

Mike Kay





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread