[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Re: Adding hierarchy


Subject: Re: [xsl] Re: Adding hierarchy
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Mon, 13 Oct 2003 07:07:59 -0700 (PDT)

> Thank you Dimitre. I see that I didn't give you enough info.
> Your solution is close but I get 
>     <lineGroup type="stanza"/> 
> when blankLine does not precede a lineGroup. 

You mean: does not *immediately* precede a line group?

If so, we need a slight change to reflect this modified requirement:


<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

 <xsl:output omit-xml-declaration="yes" indent="yes"/> 
 <xsl:strip-space elements="*"/> 

 <xsl:key name="kLGroup" match="lineGroup"
  use="generate-id(preceding-sibling::*[1])"/> 

  <xsl:template match="@* | node()"> 
    <xsl:copy> 
      <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
  </xsl:template> 

  <xsl:template 
   match="blankLine[following-sibling::*[1][self::lineGroup]]"> 
   <lineGroup type="stanza"> 
     <xsl:copy-of select="key('kLGroup', generate-id())"/> 
   </lineGroup> 
  </xsl:template> 

  <xsl:template 
   match="lineGroup[preceding-sibling::*[1][self::blankLine]]"/> 

</xsl:stylesheet> 


When this transformation is applied on your source.xml:

<text> 
  <blankLine/> 
  <lineGroup> 
    <line>  </line>
    <line>  </line>
  </lineGroup> 
  <lineGroup> 
    <line>  </line>
    <line>  </line>
    <lineGroup> 
      <line>  </line>
      <line>  </line>
    </lineGroup> 
    <line>  </line>
  </lineGroup> 
  <p/> 
  <blankLine/> 
  <p> This also happens. But does not produce a stanza.</p>
  <p/> 
  <p/> 
  <p/> 
<lineGroup> 
    <line> Make sure there is no stanza here</line>
    <line>  </line>
    <lineGroup> 
      <line>  </line>
      <line>  </line>
    </lineGroup> 
    <line>  </line>
  </lineGroup> 
  <p/> 
  <blankLine/> 
  <lineGroup> 
    <line>  </line>
    <line>  </line>
  </lineGroup> 
  <lineGroup> 
    <line>  </line>
    <line>  </line>
    <lineGroup> 
      <line>  </line>
      <line>  </line>
    </lineGroup> 
    <line>  </line>
  </lineGroup> 
  <p/> 
</text> 

the wanted result is produced:

<text>
   <lineGroup type="stanza">
      <lineGroup>
         <line/>
         <line/>
      </lineGroup>
   </lineGroup>
   <lineGroup>
      <line/>
      <line/>
      <lineGroup>
         <line/>
         <line/>
      </lineGroup>
      <line/>
   </lineGroup>
   <p/>
   <blankLine/>
   <p> This also happens. But does not produce a stanza.</p>
   <p/>
   <p/>
   <p/>
   <lineGroup>
      <line> Make sure there is no stanza here</line>
      <line/>
      <lineGroup>
         <line/>
         <line/>
      </lineGroup>
      <line/>
   </lineGroup>
   <p/>
   <lineGroup type="stanza">
      <lineGroup>
         <line/>
         <line/>
      </lineGroup>
   </lineGroup>
   <lineGroup>
      <line/>
      <line/>
      <lineGroup>
         <line/>
         <line/>
      </lineGroup>
      <line/>
   </lineGroup>
   <p/>
</text>





 


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Current Thread