Subject: Re: [xsl] Avoiding dummy xsl:if with apply-templates From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 12 Feb 2005 23:02:00 -0500 |
I find myself struggling with a construct I often need: conditionally, "else",
do something radically different depending on input.
For example:
<xsl:variable name="el" select="elements" /> <xsl:if test="count($el)">
<ul> <xsl:apply-templates select="$el" /> </ul> </xsl:if>
Here, the if statement and variable declaration exists solely to avoid an empty ul element; the special condition which occurs when the select misses.
Producing xhtml tables is a similar case. I find these common situations in XSLT programming.
These examples can be solved with usual conditional tests, as above, but I want to push the conditionalis upon the engine and write with templates; the clean, XSLT-like way. AFAICT, this made-up syntax would solve the problem:
<xsl:apply-templates select="elements"> <ul> <xsl:apply/> </ul> </xsl:apply-templates>
<xsl:if test="elements"> <ul> <xsl:apply-templates select="elements"/> </ul> </xsl:if>
Hence, when the select clause fails, the apply-templates body is not entered, and the conditionalis is not needed to be manually written and comes naturally, even.
What is the proper way of doing what I want?
-- World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Avoiding dummy xsl:if with ap, Frans Englich | Thread | Re: [xsl] Avoiding dummy xsl:if wit, Frans Englich |
[xsl] Avoiding dummy xsl:if with ap, Frans Englich | Date | Re: [xsl] Avoiding dummy xsl:if wit, Dimitre Novatchev |
Month |