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

Re: Sort XML based on Tokenized String of sort by fiel

Subject: Re: Sort XML based on Tokenized String of sort by fields
From: "Rebecca Sapir" <rsapir@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 23 May 2008 16:05:38 -0400
Re:  Sort XML based on Tokenized String of sort by fiel
Thanks Michael and Michael,

This is a great help for me. I think it is the solution that will give
me the most flexibility.  I have never done anything like this before
and this will really help me get started.

- Rebecca

Michael Kay schrieb:
>> As David suggests, I think I'd go for the approach of generating a
>> stylesheet. In effect your <REPORT_FORMAT> element defines a
>> programming language, and a good way of implementing such languages
>> often to translate them to XSLT. I've done similar things with report
>> specifications entered interactively on the screen. You're already
>> doing dynamic construction/evaluation of XPath expressions, so
>> construction of the entire stylesheet (or of the controlling
>> framework, it can always include/import a fixed module) isn't a major
>> step from that.

>I don't have the code to generate the stylesheet, but I'd like to
>propose what I imagine the result should look like.

>There is a string representation of the sorting order, captured in the
>xsl:variable $order. Then there is one generated matching template for
>each value of $order that may occur in reality. (Well, I didn't write
>the code to generate these templates, so I hand-coded one and left the
>rest up to imagination.) And there is a template to format the output
> (the copy template). Auto-generated stuff should go in one module,
>hand-coded stuff in the other one.

>Surely, this could be improved. Any comments welcome.

>Two stylesheets and XML data follow.

>Michael Ludwig

>mludwig@forelle:~/Werkstatt/xsl > expand -t2 Sapir-2008-05-22.xsl
><xsl:transform version="2.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:import href="Sapir-sorting.xsl"/>
>   <xsl:template match="REPORT">
>     <xsl:copy>
>       <ORDER-USED><xsl:value-of select="$order"/></ORDER-USED>
>       <xsl:apply-templates select="*"/>
>     </xsl:copy>
>   </xsl:template>

>mludwig@forelle:~/Werkstatt/xsl > expand -t2 Sapir-sorting.xsl
><xsl:transform version="2.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <!-- Generate this module to include all needed permutations
>   of your sort parameters. Hopefully, not too many! -->
>   <!-- sorting criteria identifier; normalize by eliminating spaces
>   <xsl:variable name="order"
>     select="translate(/REPORT/REPORT_FORMAT/ORDER_BY, ' ', '')"/>
>   <!-- just the copy template to generate output -->
>   <xsl:template match="@*|node()">
>     <xsl:copy>
>       <xsl:apply-templates select="@*|node()"/>
>     </xsl:copy>
>   </xsl:template>
>   <!-- sorting templates; should be generated -->
>   <xsl:template match="X[ $order = 'DATE,ID_1,ID_2,TYPE' ]">
>     <xsl:copy>
>       <xsl:apply-templates select="X_ROW">
>         <xsl:sort select="DATE"/>
>        <xsl:sort select="ID_1"/>
>         <xsl:sort select="ID_2"/>
>         <xsl:sort select="TYPE"/>
>       </xsl:apply-templates>
>     </xsl:copy>
>   </xsl:template>
>   <!-- more of these -->

Merlin Securities - #1 Prime Broker North America and #1 Prime Broker Single
Strategy Funds - Global Custodian 2007
#1 Prime Broker for Hedge Funds under $1 Billion - Alpha Survey 2007

This message contains information from Merlin Securities, LLC, or from one of
its affiliates, that may be confidential and privileged. If you are not an
intended recipient, please refrain from any disclosure, copying, distribution
or use of this information and note that such actions are prohibited. If you
have received this transmission in error, please notify the sender immediately
by telephone or by replying to this transmission.

Merlin Securities, LLC is a registered broker-dealer. Services offered through
Merlin Securities, LLC are not insured by the FDIC or any other Federal
Government Agency, are not deposits of or guaranteed by Merlin Securities, LLC
and may lose value. Nothing in this communication shall constitute a
solicitation or recommendation to buy or sell a particular security.

Current Thread


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.
First Name
Last Name
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.