xsl-list
[Top] [All Lists]

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

2007-09-23 09:07:40
A better solution is to use two different template rules for the two cases:

<xsl:template match="book[count(title) &lt; 2]">

</xsl:template> 

<xsl:template match="book[count(title) >= 2]">

</xsl:template>

However, I'm not clear from your description exactly what you want the two
different cases to output. Your XML structure seems a bit odd - can one book
really have two titles?

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: Alice Ju-Hsuan Wei [mailto:ajwei(_at_)indiana(_dot_)edu] 
Sent: 23 September 2007 15:55
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] [XSL]Display Different Results Based on Count 
of Node Sets

Hi,

   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, 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?

Here is the XSLT:

    <xsl:template match="book">
        <p>
            <xsl:call-template name="author"/>
            <xsl:apply-templates/>
        </p>
    </xsl:template>

     <xsl:template match="title">
        <p>
                        <xsl:apply-templates/>
        </p>
    </xsl:template>

The XML:

    <book>
     <author>Tennison, Jeni</author>
    <title>Beginning XSLT</title>
    <title>Beginning XSLT 2.0</title>
    </book>

    <book>
    <author>Meyer, Eric</author>
    <title>The Zen of CSS</title>
    </book>

Thanks to those who may be able to help.

Alice


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--