|
Subject: Re: [xsl] Sorted node set and following-sibling axis From: "Joris Gillis" <roac@xxxxxxxxxx> Date: Wed, 10 Aug 2005 19:53:25 +0200 |
What I require is the following:
<div> <p>first</p> <p>second</p> </div> <div> <p>third</p> <p>last</p> </div>
Any suggestions as to how I can achieve the desired output would be appreciated.
I've often come across this problem and I was always inclined to believe there was no solution to it. But now I seem to have found a working solution. However, as I was typing this stylesheet out, I had the faint feeling that I later on would regret having posted it...
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/>
<xsl:template match="articles"> <xsl:call-template name="group"> <xsl:with-param name="idList"> <xsl:for-each select="article"> <xsl:sort select="@priority" data-type="number" order="descending" /> <xsl:value-of select="generate-id()"/> <xsl:text>-</xsl:text> <xsl:if test="position() mod $groupSize=0 or position()=last()"> <xsl:text>|</xsl:text> </xsl:if> </xsl:for-each> </xsl:with-param> </xsl:call-template> </xsl:template>
<xsl:template name="group"> <xsl:param name="idList"/> <xsl:variable name="PartIdlist" select="substring-before($idList,'|')"/> <xsl:if test="$PartIdlist"> <div> <xsl:call-template name="animate"> <xsl:with-param name="idList" select="$PartIdlist"/> </xsl:call-template> </div> <xsl:call-template name="group"> <xsl:with-param name="idList" select="substring-after($idList,'|')"/> </xsl:call-template> </xsl:if> </xsl:template>
<xsl:template name="animate">
<xsl:param name="idList"/>
<xsl:variable name="id" select="substring-before($idList,'-')"/>
<xsl:if test="$id">
<xsl:apply-templates select="key('xID',$id)"/>
<xsl:call-template name="animate">
<xsl:with-param name="idList" select="substring-after($idList,'-')"/>
</xsl:call-template>
</xsl:if>
</xsl:template><xsl:template match="article"> <p><xsl:value-of select="title" /><xsl:value-of select="@priority" /></p> </xsl:template>
regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Vincit omnia simplicitas Keep it simple
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Sorted node set and following, Nick Fitzsimons | Thread | Re: [xsl] Sorted node set and follo, Nick Fitzsimons |
| RE: [xsl] Evaluating XSLT2 from cod, Michael Kay | Date | Re: [xsl] Sorted node set and follo, JBryant |
| Month |