[xsl] Executing an alternate template if select="somepath" returns no n odes.

Subject: [xsl] Executing an alternate template if select="somepath" returns no n odes.
From: Adam Van Den Hoven <Adam.Hoven@xxxxxxxxxxxx>
Date: Tue, 9 Jan 2001 10:40:55 -0800
I have a relatively simple question. I've already found a solution that
works for my current situation but I'm looking for a more general solution.

In my XSL, I originally had the following:

<xsl:apply-templates select="library/playlist[@current='current']" />

<xsl:template match="library/playlist[@current='current']">...

Which isn't really all that big a deal (ok, it may be redundant the way its
written but its actually someone else's code). But I need to be able to call
a different template when there is no playlist with the attribute current
equal to current. In this case, the stuff that needed to be done if there
wasn't the playlist happened to also be in the template that executes when
there is a playlist so I rewrote the code to be
<div id="used_to_be_in_the_template">
	<xsl:apply-templates />
	<xsl:call-template name="common" />
<xsl:template match="playlist[@current='current']">... </xsl:template>
<xsl:template name="common">... </xsl:template>
 (since there is no other template that will match a playlist, this works
fine, otherwise a simple mode will fix it)

But what I want to know is whether there is a way to ensure that if the
select returns no nodes that template foobar gets called. I know that I
could use a choose/when/otherwise approach but it seems inelegant to me. 

Thanks everyone. 

> 		Adam van den Hoven
> 		Internet Application Developer
> 		Blue Zone
> 		tel. 604.685.4310
> 		fax. 604.685.4391
> Blue Zone makes you interactive. http://www.bluezone.net/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread