Discussion:
Conditional with-param
Marco
2004-05-20 13:35:05 UTC
Permalink
Is it possible to do something like

<xsl:apply-templates>
<xsl:if select="condition1">
<xsl:with-param name="myparam1">
</xsl:if>
<xsl:if select="condition2">
<xsl:with-param name="myparam2">
</xsl:if>
</xsl:apply-templates>

or should I write a four-cases choose instruction, with four different
options combinations?

Marco
M. David Peterson
2004-05-23 14:24:22 UTC
Permalink
Hi Marco,

Without understanding exactly what it is you are trying to accomplish
the easiest way to solve your particular dilemma is to create a variable
outside of the xsl:apply-templates element that uses conditional logic
to determines its value. Also, to ensure that you only get one matching
value I would use an xsl:choose block to determine the value of the
variable. For example:

<xsl:variable name="foo">
<xsl:choose>
<xsl:when test="condition1">
...value if condition1 is true
</xsl:when>
<xsl:otherwise>
...value if condition1 is not true
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:apply-templates select="/foo/bar">
<xsl:with-param name="foo" select="$foo"/>
</xsl:apply-templates>

Within your matching template you would need to create a parameter
called 'foo' that would hold the value passed to it using xsl:with-param
and having the same name.

Hope this helps!

<M:D/>
-----Original Message-----
Sent: Thursday, May 20, 2004 7:35 AM
Subject: [xsl] Conditional with-param
Is it possible to do something like
<xsl:apply-templates>
<xsl:if select="condition1">
<xsl:with-param name="myparam1">
</xsl:if>
<xsl:if select="condition2">
<xsl:with-param name="myparam2">
</xsl:if>
</xsl:apply-templates>
or should I write a four-cases choose instruction, with four different
options combinations?
Marco
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--+--
Brian Chrisman
2004-05-24 18:58:09 UTC
Permalink
Post by Marco
Is it possible to do something like
<xsl:apply-templates>
<xsl:if select="condition1">
<xsl:with-param name="myparam1">
</xsl:if>
<xsl:if select="condition2">
<xsl:with-param name="myparam2">
</xsl:if>
</xsl:apply-templates>
I'm not sure what you are trying to do here.. but is it possible that
instead of having a conditional test and passing in a param, you instead
have two templates <xsl:template match="...."> which distinguish between
the two different cases in the conditional?

At that point, you could just pass both myparam1 and myparam2, (if still
necessary) without the conditional.

More info on the goal would probably help... but generally I'd suspect
using apply-templates select="..." and xsl:template match="..." will do
what you need.


That said, I believe what you are trying to do there is out of spec: (ZVON)
|<!-- Category: instruction -->
<xsl:apply-templates
select = node-set-expression
mode = qname>
<!-- Content: (xsl:sort
<http://www.zvon.org/xxl/XSLTreference/W3C/xslt.html#element-sort> |
xsl:with-param
<http://www.zvon.org/xxl/XSLTreference/W3C/xslt.html#element-with-param>)*
-->
</xsl:apply-templates>|

sort and with-param being the only recognized child elements...
Post by Marco
or should I write a four-cases choose instruction, with four different
options combinations?
Marco
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--+--
Continue reading on narkive:
Loading...