Re: [xsl] [XSL]Display Different Results Based on Count of Node Sets

Subject: Re: [xsl] [XSL]Display Different Results Based on Count of Node Sets
From: Abel Braaksma <>
Date: Sun, 23 Sep 2007 17:10:06 +0200
Alice Ju-Hsuan Wei wrote:

Below are two templates I am using to display some titles of the book. I am wondering if anybody knows whether or not I can use the count function here so that for books with multiple books by one author,

I think you mean: books with multiple titles but with one author

the titles would be broken off with the <p> tag, but those with only one, would not display the <p> tag. Anyone know if I should use <xsl:if> or the count function here?

That is quite a generic question. In general, it is probably not needed to use xsl:if. And yes, you can use the count function. When you are in the context of <book>, you can use count(title) to find out. When you design the matching template for <title>, just change it to be <xsl:template match="title[1]" to match only the first title and make a throw away generic template for the rest.

<!-- first title -->
<xsl:template match="title[1]">
   <p><xsl:apply-templates /></p>
<!-- throw away -->
<xsl:template match="title" />

If you don't want to do anything with count, this is it. Alternatively, you can simplify matters by changing your select statement instead. But that is a matter of taste and context.

-- Abel Braaksma

Current Thread