xsl-list
[Top] [All Lists]

Re: ?group? but keep order of elements

2002-10-22 13:20:44
Elke,

It turns out I had a chuckle about the "dawson"
reference, and sent the cryptic reply, but forgot to
include my silly punch-line (probably all the better).

As for your question, I assume you discovered, and
then decided against the Meunchian solution.

An alternative, then would be some recursive approach,
along the lines of:

<xsl:template match="total">
 <totlal>
  <xsl:apply-templates />
 </totlal>
</xsl:template>

<xsl:template match="entry[MAT/Fundstelle/UbNummer]">
 <xsl:if
test="not(preceding-sibling::*[1][MAT/Fundstelle/UbNummer])">
  <uebung>
   <xsl:copy-of select="." />
   <xsl:for-each
select="following-sibling::*[1][MAT/Fundstelle/UbNummer]">
    <xsl:call-template name="exercise-checker" />
   </xsl:for-each>
  </uebung>
 </xsl:if>
</xsl:template>

<xsl:template
match="entry[not(MAT/Fundstelle/UbNummer)]">
 <texteintrag>
  <xsl:copy-of select="." />
 </texteintrag>
</xsl:template>

<xsl:template name="exercise-checker">
 <xsl:copy-of select="." />
 <xsl:for-each
select="following-sibling::*[1][MAT/Fundstelle/UbNummer]">
  <xsl:call-template name="exercise-checker" />
 </xsl:for-each>
</xsl:template>

Which transforms this:

<total>
 <entry>
  <MAT>
   <Fundstelle>
    <TitelNr></TitelNr>
    <UbNummer>0</UbNummer>
   </Fundstelle>
  </MAT>
  <LO >   
   <Text></Text>
  </LO>
 </entry>
 <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>
 <entry>
  <MAT>
   <Fundstelle>
    <TitelNr></TitelNr>
    <UbNummer>2</UbNummer>
   </Fundstelle>
  </MAT>
  <LO >   
   <Text></Text>
  </LO>
 </entry>
 <entry>
  <MAT>
   <Fundstelle>
    <TitelNr></TitelNr>
    <UbNummer>3</UbNummer>
   </Fundstelle>
  </MAT>
  <LO >   
   <Text></Text>
  </LO>
 </entry>
</total>

into this:

<totlal>
   <uebung>
      <entry>
         <MAT>
            <Fundstelle>
               <TitelNr/>
               <UbNummer>0</UbNummer>
            </Fundstelle>
         </MAT>
         <LO>
            <Text/>
         </LO>
      </entry>
   </uebung>
   <texteintrag>
      <entry>
         <MAT>
            <Fundstelle>
               <TitelNr/>
            </Fundstelle>
         </MAT>
         <LO>
            <TitelEins/>
         </LO>
      </entry>
   </texteintrag>
   <uebung>
      <entry>
         <MAT>
            <Fundstelle>
               <TitelNr/>
               <UbNummer>1</UbNummer>
            </Fundstelle>
         </MAT>
         <LO>
            <Text/>
         </LO>
      </entry>
      <entry>
         <MAT>
            <Fundstelle>
               <TitelNr/>
               <UbNummer>2</UbNummer>
            </Fundstelle>
         </MAT>
         <LO>
            <Text/>
         </LO>
      </entry>
      <entry>
         <MAT>
            <Fundstelle>
               <TitelNr/>
               <UbNummer>3</UbNummer>
            </Fundstelle>
         </MAT>
         <LO>
            <Text/>
         </LO>
      </entry>
   </uebung>
</totlal>

(some fine-tuning would still help)

Bryan

--- "Naraschewski, E." <e(_dot_)naraschewski(_at_)klett-mail(_dot_)de>
wrote:
Hallo again,
(my first mail today somehow did not get through to
the list)
again I read through the faqs (to Bryan S. Schnabel:
the list with the p in it) and without any result.
There are partly answers but not the answer I am
looking for. I am not sure whether grouping is the
right direction. 
I can not really fix a position. I can only say: Use
the node <texteintrag> for all entries up to the
next <uebung>, than take the node <uebung> up to the
point where <texteintrag> starts again. Actually I
would think of xsl:if or xsl:when, but if I choose
these how can I keep the strucure? I simply need an
xslt that transforms my xml, adds new elements and
comprises the child elements and following siblings.
Do I need something completely different to my
stylesheet or is there a way to continue?
. . .
Thanks in advance
Elke

*******************************************************
Elke Naraschewski - Ernst Klett Verlag GmbH -
Leistungscenter Mediengestaltung

Rotebühlstr. 77 - 70178 Stuttgart
Tel.: 0711/6672-1116 - Fax: 0711/6672-2023 - E-mail:
e(_dot_)naraschewski(_at_)klett-mail(_dot_)de

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



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



<Prev in Thread] Current Thread [Next in Thread>