|
Subject: [xsl] group but keep order of elements From: "Naraschewski, E." <e.naraschewski@xxxxxxxxxxxxx> Date: Mon, 21 Oct 2002 18:00:21 +0200 |
Hallo,
and sorry for my simple question. I wasn`t able to get the answer at dawson or in the archive. I am not a programmer, just a person in a publishers house dealing with xml exports and now with the need of gaining any xslt knowlegde.
My problem is always the beginning, where to start.
A few weeks ago I had a question concerning adding elements. I have an xml document with numerous entries. Some do have the element <UbNummer> and some don`t.
Therefore I needed a solution to add a new element <texteintrag> to these elements without <UbNummer>. I continued with adding the element <uebung> at the equivilant position before the entry with <UbNummer>.
Now I was asked whether it is possible to put the elements <texteintrag> and <uebung> not around every entry, but around all entries up to the next change. Actually it is grouping, but I do not know how to keep the order of my entries. Is it possible to continue from where I am now or do I have to change my code entirely?
The wanted result:
<total>
<texteintrag>
<entry>
<MAT>
<Fundstelle>
<TitelNr></TitelNr>
</Fundstelle>
</MAT>
<LO>
<TitelEins></TitelEins>
</LO>
</entry>
<entry>
<MAT>
<Fundstelle>
<TitelNr></TitelNr>
</Fundstelle>
</MAT>
<LO>
<TitelEins></TitelEins>
</LO>
</entry>
...
</texteintrag>
<uebung>
<entry>
<MAT>
<Fundstelle>
<TitelNr></TitelNr>
<UbNummer>1</UbNummer>
</Fundstelle>
</MAT>
<LO >
<Text></Text>
</LO>
<entry>
<MAT>
<Fundstelle>
<TitelNr></TitelNr>
<UbNummer>1</UbNummer>
</Fundstelle>
</MAT>
<LO >
<Text></Text>
</LO>
</entry>
...
</uebung>
<texteintrag>
...
</texteintrag>
<uebung>
...
</uebung>
...
</total>
The Original:
<total>
<entry>
<MAT>
<Fundstelle>
<TitelNr></TitelNr>
</Fundstelle>
</MAT>
<LO>
<TitelEins></TitelEins>
</LO>
</entry>
<entry>
<MAT>
<Fundstelle>
<TitelNr></TitelNr>
<UbNummer>1</UbNummer>
</Fundstelle>
</MAT>
<LO >
<Text></Text>
</LO>
</entry>
...
</total>
My stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:template match="entry[not(MAT/Fundstelle/UbNummer)]">
<xsl:copy>
<texteintrag>
<xsl:apply-templates/>
</texteintrag>
</xsl:copy>
</xsl:template>
<xsl:template match="entry[(MAT/Fundstelle/UbNummer)]">
<xsl:copy>
<uebung>
<xsl:apply-templates/>
</uebung>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
After the transformation:
<total>
<entry>
<texteintrag>
<MAT>
<Fundstelle>
<TitelNr></TitelNr>
</Fundstelle>
</MAT>
<LO>
<TitelEins></TitelEins>
</LO>
</texteintrag>
</entry>
<entry>
<uebung>
<MAT>
<Fundstelle>
<TitelNr></TitelNr>
<UbNummer>1</UbNummer>
</Fundstelle>
</MAT>
<LO >
<Text></Text>
</LO>
</uebung>
</entry>
...
</total>
Even if it is simple I would be quite happy to recieve an answer.
Best Regards
Elke Naraschewski
*******************************************************
Elke Naraschewski - Ernst Klett Verlag GmbH -
Leistungscenter Mediengestaltung
Rotebühlstr. 77 - 70178 Stuttgart
Tel.: 0711/6672-1116 - Fax: 0711/6672-2023 - E-mail:
e.naraschewski@xxxxxxxxxxxxx
Stuttgart HRB 10746 - Verleger: Dr.h.c. Michael Klett
Geschäftsführer: Johannes Leßmann - Harald Melcher - Dr. Tilmann Michaletz - Dr. Wolf Unkelbach (Vorsitz)
*******************************************************
Elke Naraschewski - Ernst Klett Verlag GmbH -
Leistungscenter Mediengestaltung
Rotebühlstr. 77 - 70178 Stuttgart
Tel.: 0711/6672-1116 - Fax: 0711/6672-2023 - E-mail:
e.naraschewski@xxxxxxxxxxxxx
Stuttgart HRB 10746 - Verleger: Dr.h.c. Michael Klett
Geschäftsführer: Johannes Leßmann - Harald Melcher - Dr. Tilmann Michaletz - Dr. Wolf Unkelbach (Vorsitz)
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] How determinate what is t, Eike Jordan | Thread | [xsl] Problem caused by Name space, Jeff Nester |
| [xsl] How determinate what is the p, Giovani Librelotto | Date | [xsl] Problem caused by Name space, Jeff Nester |
| Month |