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

Re: How to sort this xml out

Subject: Re: How to sort this xml out
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 9 May 2001 18:20:41 +0100
Re:  How to sort this xml out
Hi Sri,

> I want to sort all the replies which previousID == a messageID and
> to group them under an tag called <content>

The first thing is that you need to be able to quickly jump from a
Message id to the Reply elements that have that Message as a parent.
So you want to index the Reply elements according to their parentID:

<xsl:key name="replies" match="Reply" use="parentID" />

Within the Main-matching template, you want to only apply templates to
the Message elements, not to the Reply elements:

<xsl:template match="Main">
   <Main>
      <xsl:apply-templates select="Message" />
   </Main>
</xsl:template>

Within the Message-matching template, you need to check whether the
Message has any replies or not, and do the appropriate thing as a
result of that check.  You can get the replies to the message using
the key that you've set up.

<xsl:template match="Message">
   <!-- retrieve the replies to the message -->
   <xsl:variable name="replies" select="key('replies', id)" />
   <xsl:choose>
      <!-- if there are any... -->
      <xsl:when test="$replies">
         <!-- ...create a Content element... -->
         <Content>
            <!-- ...copy in the content of this Message... -->
            <xsl:copy-of select="*" />
            <!-- ...and add the content of the replies... -->
            <xsl:copy-of select="$replies/*" />
         </Content>
      </xsl:when>
      <xsl:otherwise>
         <!-- otherwise, copy the whole message -->
         <xsl:copy-of select="." />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

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

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.