This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: adding multiple variables to a complex condition
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Eric Smith <Eric dot Smith at fruitcom dot com>
- Cc: XSL List <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 10 Dec 2001 11:02:19 +0000
- Subject: Re: [xsl] adding multiple variables to a complex condition
- Organization: Jeni Tennison Consulting Ltd
- References: <20011208221223.B22685@apple.fruitcom.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Eric,
> What is a good way to add other variables like output2 .. $outputn
> to this conditional?
Yes. Use an XML structure to hold the various names:
<output>output1</output>
<output>output2</output>
...
<output>outputN</output>
Hold these output elements in a node set called $outputs. This enables
you to check if *any* or *none* of the outputs fulfil certain
conditions, because it's easy to check whether *any* or *no* node
fulfils conditions. For example:
$outputs = 'all'
would check whether *any* output had the value 'all'.
How you get the $outputs variable holding those output elements is up
to you. The purest way would be to put them in a separate document or
in the stylesheet and use the document() function to get at them.
Alternatively, you could build a variable and an extension node-set()
function to get at them.
I'm not sure that I follow the logic of your condition, but I think
you want something like the following:
<xsl:template name="conditional">
<xsl:variable name="include" select="@include" />
<xsl:variable name="exclusive" select="@exclusive" />
<xsl:variable name="reject" select="@reject" />
<xsl:choose>
<xsl:when test="
$outputs = 'all' or
((ancestor::*|@*)[name() = $outputs] or
$outputs[contains($include, .)] or
$outputs[contains($exclusive, .) and
not(contains($reject, .))] and
not($reject = 'all'))">yes</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Note that you need to do $outputs[contains($include, .)] rather than
contains(@include, $outputs) because the contains() function converts
the second argument to a string, so contains(@include, $outputs) would
test whether the include attribute contains the first output, not any
of the others.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list