Subject: Re: [xsl] use-when From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Thu, 09 Dec 2010 18:55:39 -0500 |
I cannot figure out how to use use-when attribute, beyond standard "system-property('file-separator')" example.
There are no syntactic constraints on the XPath expression that can be used as the value of the use-when attribute. However, there are severe constraints on the information provided in its evaluation context. These constraints are designed to ensure that the expression can be evaluated at the earliest possible stage of stylesheet processing, without any dependency on information contained in the stylesheet itself or in any source document.
My code is overflown w/ "conditional" templates like:
<xsl:template match="some-xpath1[$file-set='A']"> <xsl:template match="some-xpath2[$file-set='B']"> <xsl:template match="some-xpath3[$file-set='C']">
$file-set is declared as parameter, but it is not really a parameter, it is the same for all files converted in a set, other parameters vary for each file.
I think System.setProperty("file-set", "A") is not a good choice, because there can be many transforms running in the background.
How to properly rewrite above "pseudo" use-when to "true" use-when, i.e.: <xsl:template match="some-xpath1" use-when="user-property('file-set')='A'"> p.s. I use Saxon-9 HE
<xsl:choose> <xsl:when test="$file-set='A'"> <xsl:apply-templates mode="file-set-A"/> </xsl:when> <xsl:when test="$file-set='B'"> <xsl:apply-templates mode="file-set-B"/> </xsl:when> <xsl:when test="$file-set='C'"> <xsl:apply-templates mode="file-set-C"/> </xsl:when> </xsl:choose>
<xsl:template match="some-xpath1" mode="file-set-A"> <xsl:template match="some-xpath2" mode="file-set-B"> <xsl:template match="some-xpath3" mode="file-set-C">
-- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] use-when, Andriy Gerasika | Thread | Re: [xsl] use-when, Andriy Gerasika |
[xsl] use-when, Andriy Gerasika | Date | Re: [xsl] Random number seed genera, Michel Hendriksen |
Month |