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

Re: Sorted node set and following-sibling axis

Subject: Re: Sorted node set and following-sibling axis
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Wed, 10 Aug 2005 19:53:25 +0200
xsl axis following sibling
Hi Nick,

Tempore 19:11:02, die 08/10/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Nick Fitzsimons <nick@xxxxxxxxxxxxxx>:

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...

here's the xsl:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="xID" match="article" use="generate-id()"/>

<xsl:variable name="groupSize" select="2"/>

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

</xsl:stylesheet>


regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Vincit omnia simplicitas Keep it simple

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.