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



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...

:) ?

-e

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

Ilpide, Emmanuel writes:
 > Hi!
 > 
 > I get a XML document containing (at some level in the doc): 
 > 
 > <XXX action="delete">
 > 
 >       <old>
 > 
 >             old_data
 > 
 >       </old>
 > 
 > </XXX>
 > 
 > <XXX action="add">
 > 
 >       new_data
 > 
 > </XXX>
 > 
 >  
 > 
 > ... and I'd need to transform this into the following:
 > 
 >  
 > 
 > <XXX action="modify">
 > 
 >       <old>
 > 
 >             old_data
 > 
 >       </old>
 > 
 >       new_data
 > 
 > </XXX>
 > 
 >  
 > 
 > I've been looking into what XSLT can provide but it's not very clear
 > whether this is actually do-able or not... 
 > 
 > Any idea?
 > 
 > Cheers!


        It's doable. It's even quite straightforward. Assuming that
the original XXX tags are wrapped in an outer tag OUTER, you could use
something like the following:

  <xsl:template match="OUTER">
    <XXX action="modify">
      <old>
        <xsl:apply-templates select="XXX[ action='delete']/old"/>
      </old>
      <xsl:apply-templates select="XXX[ action='add']"/>
    </XXX>
  </xsl:template>
  
  <xsl:template match="XXX">
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="XXX/old">
    <xsl:value-of select="."/>
  </xsl:template>

_______________________________________________
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]