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


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