[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|