Generating XSLT from XSLT
You want to generate XSLT from a different XML representation. Alternatively, you want to transform XSLT or pseudo-XSLT into real XSLT.
Two things about the control structure of XSLT sometimes annoy me.
The first is the absence of an
construct; the second is the absence of a true looping construct. Of
course, I am aware of
xsl:for-each, but each is lacking to some extent.
xsl:choose annoying because the
choose element serves practically no function,
except to force an extra level of nesting. The
xsl:for-each is not really a looping construct but
an iteration construct. To emulate loops with counters, you have to
use recursion or the Piez method (see Recipe 1.5),
which is awkward.
This example illustrates an XSLT-to-XSLT generation by pretending
that XSLT has the elements
it really does not, you will create a stylesheet
generates true XSLT from the following pseudo-XSLT. Having an
xsl:if and an
awkward, but it would be wrong to use the standard XSLT namespace for
your extended elements; these elements might be defined in standard
XSLT some day:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xslx="http://www.ora.com/XSLTCookbook/ExtendedXSLT" > <xsl:output method="text"/> <xsl:template match="foo"> <xslx:if test="bar"> <xsl:text>You often will find a bar in the neighborhood of foo!</xsl:text> </xslx:if> ...