[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: grouping content

Subject: Re: grouping content
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 6 Apr 2001 09:27:35 +0100
atom location element
Hi Gavin,

Other people have shown how to do grouping with your data.  Just to
point out that in:

> In xsl I was thinking of doing this:
> <xsl:choose>
>         <xsl:when test="@Location=$Location">
>         </xsl:when>
>         <xsl:otherwise>
>         <xsl:param name="Location" select="@Location"/>
>         <br/>Location <xsl:value-of select="$Location"/>
>         </xsl:otherwise>
> </xsl:choose>
> <br/><xs:value-of select="@Value"/>
>
> For some reason it will go straight to the otherwise and not even
> look at the test. So I get this:

I think you're trying to do some kind of updating of the $Location
variable with each step.  One of the important lessons to learn about
XSLT is that variables and parameters in XSLT cannot be changed once
they're set.

However, you could create a recursive template with the same kind of
logic as you have in the above.  You could step through the Location
elements one by one, passing in the Area of one Location when you
apply templates to the next:

<xsl:template match="Location">
   <xsl:param name="Location" select="@Area" />
   <xsl:if test="@Area != $Location">
      <br />Location <xsl:value-of select="@Area" />
   </xsl:if>
   <br /><xsl:value-of select="@Value" />
   
   <!-- apply templates to the next Location element, this time with
        the $Location parameter set to the (new) @Area -->
   <xsl:apply-templates select="following-sibling::Location[1]">
      <xsl:with-param name="Location" select="@Area" />
   </xsl:apply-templates>
</xsl:template>

To start the process, you have to apply templates to the first
Location element *only*:

   <xsl:apply-templates select="Location[1]" />

However, the usual method in XSLT is to apply templates to everything,
and try to work out what to do given the information you have about
the one thing you're processing at the moment. In this case, you would
have a single template for a Location element. Each Location element
can work out whether to add a Location heading by checking its
immediately preceding sibling Location's Area attribute - if it's
different from this one, then you need to add the Location heading:

<xsl:template match="Location">
   <xsl:if test="@Area != preceding-sibling::Location[1]/@Area">
      <br />Location <xsl:value-of select="@Area" />
   </xsl:if>
   <br /><xsl:value-of select="@Value" />
</xsl:template>

Note that these solutions *only* work because you've already got the
Location elements sorted in order.  The other solutions you've been
given, using the Muenchian Method, work whatever the order of the
Location elements.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread
  • grouping content
    • Gavin Myers - Thu, 5 Apr 2001 17:01:57 -0400 (EDT)
      • David Carlisle - Thu, 5 Apr 2001 18:45:29 -0400 (EDT)
      • Tim Watts - Thu, 5 Apr 2001 20:03:36 -0400 (EDT)
      • Jeni Tennison - Fri, 6 Apr 2001 04:28:38 -0400 (EDT) <=
      • <Possible follow-ups>
      • Dan Diebolt - Thu, 5 Apr 2001 21:33:59 -0400 (EDT)
      • Yang - Thu, 5 Apr 2001 22:08:58 -0400 (EDT)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.