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

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="."/>
</xsl:for-each>
</xsl:template>

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']" />
                </xsl:for-each>
                
Assuming this document structure:

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

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

jr



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


Current Thread