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

xsl sort query

Subject: xsl sort query
From: Cormac Fiddes <Cormac.Fiddes@xxxxxx>
Date: Fri, 29 Aug 2003 16:00:41 +0100 (WET-DST)
sort query
Hi,
I have the following stylesheet & xml data and I need to dynamically sort the
data coming from the xml file.

There is a need to sort on 'if' basis, i.e.  a value(CFIndica) coming from the
xml file within a different group(HEADINGS) determines the sort. I.E. 

I need to sort by
when CFIndica = 1 then sort by cfnumber ascending
when CFIndica = 2 then sort by cfsurname ascending
when CFIndica = 3 then sort by cfcentre ascending.
AND to allow a default of 'NO' sort, i.e CFIndica might be = 4 or just have a
default of no sort.(perhaps just not apply CFIndica of 1 to 3?).

I had thought it would be something like this, but sadly no effect.
The xml data is like this,


 <GROUP_MEMBER_DETAILS>
         <CFNumber>18888</CFNumber>
         <CFTitle>Mr</CFTitle>
         <CFFirstName>Cormac</CFFirstName>
         <CFSurname>GGGGGG</CFSurname>
         <CFIden>XX999</CFIden>
         <CFCentre>1122</CFCentre>
         <CFProd>Plan B</CFProd>
         <CFCov>Hsteps</CFCov>
         <CFAdu>6</CFAdu>
         <Students>5</Students>
         <Children>7</Children>
         <Status>A</Status>
      </GROUP_MEMBER_DETAILS>

      <GROUP_MEMBER_DETAILS>
         <CFNumber>12345</CFNumber>
         <CFTitle>Mr</CFTitle>
         <CFFirstName>Cormac</CFFirstName>
         <CFSurname>AAAAAA</CFSurname>
         <CFIden>XX999</CFIden>
         <CFCentre>1122</CFCentre>
         <CFProd>Plan B</CFProd>
         <CFCov>Hsteps</CFCov>
         <CFAdu>6</CFAdu>
         <Students>5</Students>
         <Children>7</Children>
         <Status>A</Status>
      </GROUP_MEMBER_DETAILS>

      <GROUP_MEMBER_DETAILS>
         <CFNumber>14444</CFNumber>
         <CFTitle>Mr</CFTitle>
         <CFFirstName>Cormac</CFFirstName>
         <CFSurname>CCCCCC</CFSurname>
         <CFIden>XX999</CFIden>
         <CFCentre>1122</CFCentre>
         <CFProd>Plan B</CFProd>
         <CFCov>Hsteps</CFCov>
         <CFAdu>6</CFAdu>
         <Students>5</Students>
         <Children>7</Children>
         <Status>A</Status>
      </GROUP_MEMBER_DETAILS>

      <GROUP_MEMBER_DETAILS>
         <CFNumber>16666</CFNumber>
         <CFTitle>Mr</CFTitle>
         <CFFirstName>Cormac</CFFirstName>
         <CFSurname>EEEEEE</CFSurname>
         <CFIden>XX999</CFIden>
         <CFCentre>1122</CFCentre>
         <CFProd>Plan B</CFProd>
         <CFCov>Hsteps</CFCov>
         <CFAdu>6</CFAdu>
         <Students>5</Students>
         <Children>7</Children>
         <Status>A</Status>
      </GROUP_MEMBER_DETAILS>

      <GROUP_MEMBER_DETAILS>
         <CFNumber>15555</CFNumber>
         <CFTitle>Mr</CFTitle>
         <CFFirstName>Cormac</CFFirstName>
         <CFSurname>DDDDDD</CFSurname>
         <CFIden>XX999</CFIden>
         <CFCentre>1122</CFCentre>
         <CFProd>Plan B</CFProd>
         <CFCov>Hsteps</CFCov>
         <CFAdu>6</CFAdu>
         <Students>5</Students>
         <Children>7</Children>
         <Status>A</Status>
      </GROUP_MEMBER_DETAILS>

      <GROUP_MEMBER_DETAILS>
         <CFNumber>19999</CFNumber>
         <CFTitle>Mr</CFTitle>
         <CFFirstName>Cormac</CFFirstName>
         <CFSurname>HHHHHH</CFSurname>
         <CFIden>XX999</CFIden>
         <CFCentre>1122</CFCentre>
         <CFProd>Plan B</CFProd>
         <CFCov>Hsteps</CFCov>
         <CFAdu>6</CFAdu>
         <CFStu>5</CFStu>
         <CFChi>7</CFChi>
         <CFSta>A</CFSta>
      </GROUP_MEMBER_DETAILS>

I need to sort by
when CFIndica = 1 then sort by cfnumber ascending
when CFIndica = 2 then sort by cfsurname ascending
when CFIndica = 3 then sort by cfcentre ascending.
AND to allow a default of 'NO' sort, i.e CFIndica might be = 4 or just have a
default of no sort.(perhaps just not apply CFIndica of 1 to 3?).

I had thought the xsl would be like:

<!--
Define sorting in details
-->
<xsl:template match="CF_DETAILS">
	<xsl:variable name="CFOption">
		<xsl:value-of select="string(HEADINGS//CFIndica)"/>
	</xsl:variable>
	<xsl:if test="$CFOption=1">
		<xsl:apply-templates>
			<xsl:sort select="CFNumber" order="ascending"
data-type="number"/>
		</xsl:apply-templates>
	</xsl:if>
	<xsl:if test="$CFOption=2">
		<xsl:apply-templates>
			<xsl:sort select="CFSurname" order="ascending"
data-type="number"/>
		</xsl:apply-templates>
	</xsl:if>
	<xsl:if test="$CFOption=3">
		<xsl:apply-templates>
			<xsl:sort select="CFCentre" order="ascending"
data-type="number"/>
		</xsl:apply-templates>
	</xsl:if>
</xsl:template>

<!--
Define the elements that are required within the block CF_DETAILS
-->
<xsl:template match="CF_DETAILS">
  <CF_DETAILS>
	<xsl:call-template name="G_CF_DETAILS"/>		
	<xsl:apply-templates select="descendant::CFNumber"/>
	<xsl:apply-templates select="descendant::CFTitle"/>
	<xsl:apply-templates select="descendant::CFFirstname"/>
	<xsl:apply-templates select="descendant::CFSurname"/>
	<xsl:apply-templates select="descendant::CFIden"/>
	<xsl:apply-templates select="descendant::CFCentre"/>
	<xsl:apply-templates select="descendant::CFProd"/>
	<xsl:apply-templates select="descendant::CFCov"/>
	<xsl:apply-templates select="descendant::CFStu"/>
	<xsl:apply-templates select="descendant::CFStu"/>
	<xsl:apply-templates select="descendant::CFStu"/>
  </CF_DETAILS>	
</xsl:template>

<!--
call template CF_DETAILS
-->

<xsl:template name="G_CF_DETAILS">
	<xsl:element name="CF_DETAILS">
  		<xsl:attribute name="xfa:dataNode">dataGroup</xsl:attribute>
  		<xsl:text>begin</xsl:text>
	</xsl:element>
</xsl:template>

Please help out, as this is really bugging me!

cheers
Cormac

Cormac Fiddes,
Software Development,
Abbey St.

Ext: 4386

Direct Line: 01-7994009

E-Mail : Cormac.Fiddes@xxxxxx

http://www.vhihealthe.com
http://www.vhihealthcare.com
_____________________________

************************************************************	
This e-mail and any files transmitted with it contain information which may be
confidential and which may also be privileged and is intended solely for the
use of the individual or entity to whom it is addressed.  Unless you are the
intended recipient you may not copy or use it, or disclose it to anyone else.
Any opinions expressed are that of the individual and not necessarily that of
Vhi Healthcare. If you have received this e-mail in error please notify the
sender by return. This footnote also confirms that this e-mail message has been
Swept for the presence of computer viruses.



 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.