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

Dynamically controlling sort order based on values in

Subject: Dynamically controlling sort order based on values in the XML
From: "Steve W" <lsl@xxxxxxxxxxxxx>
Date: Fri, 3 Jun 2005 10:27:37 +0100
sort order id
I have some xml that looks like :

<DISPLAY>
    <CONFIG>
        <COL>
            <ID>ColA</ID>
            <ORDERBY DIRECTION="ASC">1</ORDERBY>
        </COL>
        <COL>
            <ID>ColB</ID>
            <ORDERBY DIRECTION="DSC">2</ORDERBY>
        </COL>
    </CONFIG>
    <DATA>
        <ROW>
            <COL ID="ColA">
                <VALUE>BBB</VALUE>
            </COL>
            <COL ID="ColB">
                <VALUE>111</VALUE>
            </COL>
        </ROW>
        <ROW>
            <COL ID="ColA">
                <VALUE>CCC</VALUE>
            </COL>
            <COL ID="ColB">
                <VALUE>333</VALUE>
            </COL>
        </ROW>
        <ROW>
            <COL ID="ColA">
                <VALUE>AAA</VALUE>
            </COL>
            <COL ID="ColB">
                <VALUE>222</VALUE>
            </COL>
        </ROW>
    </DATA>
</DISPLAY>

I have a stylesheet that outputs the data sorted by the element in CONFIG
where COL/ORDERBY/text() is 1,  which looks like :

<xsl:template match="DISPLAY">
   <xsl:variable name="sort_col"
select="CONFIG/COL[ORDERBY/text()='1']/ID/text()" />
   <xsl:apply-templates select="DATA/ROW" mode="do_data">
      <xsl:sort select="COL[@ID=$sort_col]/VALUE/text()" />
   </xsl:apply-templates>
</xsl:template>

<xsl:template match="ROW" mode="do_data">
   <xsl:value-of select="COL[@ID='ColA']/VALUE/text()" />, <xsl:value-of
select="COL[@ID='ColB']/VALUE/text()" />
   <br />
</xsl:template>

This gives me :
AAA, 222
BBB, 111
CCC, 333

I need to be able to sort the data based on the CONFIG element of the XML
and I don't know ahead of time how many columns there are going to be in the
dataset and how many of them I will need to sort by.

Can anyone suggest a way to achive this ?

Thanks

Steve

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.