RE: [xslt] Concatenating blocks (and a bit more) with XSLT



Quite smart.. ;) It does work... ;) Thanx

But now, how could I make that generic so that it works on XXX blocks
but also on YYY, ZZZ... w/o duplicating the code ?

Challenging? ;)

-e

-----Original Message-----
From: xslt-bounces gnome org [mailto:xslt-bounces gnome org] On Behalf
Of Igor Zlatkovic
Sent: 27 May 2004 15:54
To: The Gnome XSLT library mailing-list
Subject: Re: [xslt] Concatenating blocks (and a bit more) with XSLT

On 27.05.2004 15:05, Ilpide, Emmanuel wrote:

> Cool! Thanx it does work (with copy-of instead of value-of)... but
what
> if I want to do the following:
>  * if I have only one of the two blocks (add/delete), these are just
> copied 
>  * if I have the two of them, I concatenate...
> 
> :) ?

Assuming 'delete' always comes first, then use a <xsl:if> to test for 
'add' element along the following-sibling axis.

   <xsl:template match="XXX[ action = 'delete']">
     <xsl:choose>
       <xsl:when test="following-sibling::XXX
           [ action = 'add'][position()=1]">
         <XXX action="modify">
            <xsl:copy-of select="old"/>
            <xsl:apply-templates select="following-sibling::XXX
                [ action = 'add'][position()=1]"/>
         </XXX>
       </xsl:when>
       <xsl:otherwise>
         <xsl:copy-of select="."/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>

   <xsl:template match="XXX[ action = 'add']">
     <xsl:choose>
       <xsl:when test="preceding-sibling::XXX
           [ action = 'delete'][position()=1]">
       </xsl:when>
       <xsl:otherwise>
         <xsl:copy-of select="."/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>


Ciao,
Igor
_______________________________________________
xslt mailing list, project page http://xmlsoft.org/XSLT/
xslt gnome org
http://mail.gnome.org/mailman/listinfo/xslt


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]