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

Re: Re-ordering elements

Subject: Re: Re-ordering elements
From: John Robert Gardner <jrgardn@xxxxxxxxx>
Date: Thu, 20 Jan 2000 13:10:24 -0500 (EST)
xsl sort by id
I've been out of town and so was unable to --hopefully-- bring closure to
the topic of a week ago.  I was working with a bunch of one-line mantra's
from a text, each of which has a traditional specific id reference that
all scholars working with the text know well--even intuitively.  E.g., the
first line of the Rig Veda as id="rv1.1.1a" and the second line
id="rv1.1.1b," and so on.

There is a sanskrit tradition for an XSL/T-like transformation of the
order of mantras, taken from a multitude of often-non-contiguous places in
teh document.  IN the example I poorly, as it turns out, expressed and
David waded through, I had 1.14.1a, to be followed by 1.84.1a, then
1.14.1b, followed by 1.84.1b (I think the actual verses might have been
different, but that's the general idea), and so on up to say
1.14.1e/1.84.1e, in alternation between hymns 14 and 84 as mentioned

Thus, I did want to know if there is some way to _very simply_ select an
order such as 1.1.1e, to be followed by 3.62.10a, to be followed by
1.164.2a, then 1.84.10b, etc.  My concern--even though David's fix is
great (see below), is that "sort" is not going to work for this.  So I
turn to his kind response:

On Wed, 12 Jan 2000, David Carlisle wrote:

> > Why can't I just list the mantra's in the order I want to output them, by
> > id number, with--for instance, "xsl:copy-of select="mantra[@id='1.2.3a'"
> > and then the next one I want and so on, all in one xsl:template?   This
> > just seems easier.
> You can. That's what my posting did, however you need in this case to
> use substring to define the sorting order. But this is _only_ because
> you have complicated the issue by using id strings that you want sorting
> but can neither be sorted numerically nor lexicographically. For example
> if your atributes were just  1, 2, 3, 4, you could output all the manra
> sorted by that attribute. But no system is going to be able to sort
> in the order 1.2.3a 1.2.4a 1.2.3b 1.2.4b without you writing some code
> to split up the strings into two parts so the a b c suffix can be sorted
> first. 

In other words, is "sort" the only way?  And, if so, why is it not
possible to use the unique id's to simply pick this, then that, then the
other thing?  You see, the RV is several megabytes, and has 1000's of
mantra's.  I want to make a simple XSL/T script that a scholar can copy as
many times as possible, changing the id to be selected each time, within
the same .xsl file.  I'm ever more conscious with each passing email on
this that I'm missing something obvious, but I really did try quite a few
options, and it only just so happened that the one example was applicable
to an ordered sort.  So David's fix works:

<xsl:template match="sample">
<xsl:for-each select="verse/mantra">
<xsl:sort select="substring-after(@id,../@id)"/>
<xsl:sort select="../@id" order="descending"/>
<xsl:copy-of select="."/>

Could I do this for the non-continquous example:

    <xsl:for-each select="mantra" >
                <xsl:sort select="[@id='rv1.84.10a']" />
                <xsl:sort select="[@id='rv3.62.10c']" />
                <xsl:sort select="[@id='rv1.164.1a']" />
                <xsl:sort select="[@id='rv1.164.1e']" />
                <xsl:sort select="[@id='rv1.14.1a']" />
Assuming this document structure:

<mandala id="rv1">
<hymn id="rv1.1">
<verse id="rv1.1.1">
<mantra id="rv1.1.1a"> PCDATA
... more mantra's here ---
... more verses here ---
... more hymns here --
... more mandala's here ---

Many kinds thanks to all on this, most especially the inimitable D.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

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.