This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
sorting and merging
- To: xsl-list at lists dot mulberrytech dot com
- Subject: [xsl] sorting and merging
- From: Riboni Ugo <Ugo dot Riboni at Fiditalia dot it>
- Date: Tue, 3 Apr 2001 14:24:48 +0200
- Reply-To: xsl-list at lists dot mulberrytech dot com
hi everybody,
i'm new ot this list but maybe someone can can give me some help
to solve this problem i have.
(sorry if the explanation is going to be lengthy, but i had not found
a more concise way to express what i need to do. i hope this helps
clarity, thought.)
in my application (server side) i create an xml fragment from random
user input, then i need to merge it into a "main" xml document after
sorting it.
the structure of my main xml doc looks like:
("main.xml")
<ex>
<qs>
<q type="S">
<as>
<a>txt</a>
{...more <a>...}
</as>
</q>
{...more <q>...}
</qs>
</ex>
and the fragments i need to merge look like:
<temproot>
<a new="3">txt</a>
<a new="1">txt</a>
<a new="2">txt</a>
</temproot>
What i need to do is to first sort the <a>'s in the fragment based on the
"new" attribute,
then insert them in the main xml file *replacing* all the old <a>'s.
To make it simple suppose i wish to insert them always as childs of the
first <q> in the main xml doc. (i think i can parametrize this later).
Also i need, quite obviously, to remove the "new" attribute from the result,
since it's useful only as a sort device and not to the final xml.
Currently what i do is to create load the fragment in the processor and sort
the <a>'s with
a stylesheet like this one (boilerplate stuff killed):
<xsl:template match='/'>
<xsl:apply-templates select="/temproot"/>
</xsl:template>
<xsl:template match='@* | node()'>
<xsl:copy>
<xsl:apply-templates select='@*[not(name()="new")] | node()'
>
<xsl:sort select="@new" data-type="number"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
after this i have to resort to the loading the main xml and the sorted
fragment in two DOMs and then "manually" strip all the childs <a>'s of
the designated <q> and insert the new <a>'s in their place.
My idea is to use document() to load the main xml in the above stylesheet
and
use it to perform also the part i currently do via the DOM, but so far i had
not been able to write a working stylesheet that does this.
Can someone please throw an hint at me ? Just an idea on how to tackle this
problem or some pieces of example stylesheet would be greatly appreciated.
Thanks in advance,
Ugo R.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list