Re: [xsl] Reformatting

Subject: Re: [xsl] Reformatting
From: Dan Diebolt <dandiebolt@xxxxxxxxx>
Date: Thu, 10 May 2001 21:11:46 -0700 (PDT)
The enclosed xslt produces "1-4,10-13,24".

This is an absolutely horrible solution, but it works if you would
accept output such as "1-2,6-7,10-13,24". I sense a certain similarity
to the recent problem of needing to wrap child elements in <p> 
tags but not wrapping a child which is a <p> element. 

This is a class of problem which would simple in a procedural language 
but difficult in a functional language where you are trying to process
similarities or differences between successive elements. 

Could someone offer a more elegant classification of the difficulty?

Regards,

Dan
----------------------------
<?xml version="1.0"?>

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

<xsl:template match="/">
 <xsl:apply-templates select="T1"/>
</xsl:template>

 <xsl:template match="T1">
  <xsl:variable name="result">
   <xsl:for-each select="ch">
    <xsl:variable name="p1" select="number(.)"/><br/>
    <xsl:variable name="p2" select="number(preceding-sibling::*[1])+1"/><br/>
    <xsl:variable name="p3" select="number(following-sibling::*[1])-1"/><br/>
    <xsl:choose>
     <xsl:when test="$p1=$p2 and $p1=$p3">-</xsl:when>
     <xsl:when test="$p1=$p3"><xsl:value-of select="."/>-</xsl:when>
     <xsl:when test="position()=last()"><xsl:value-of select="."/></xsl:when>
     <xsl:otherwise><xsl:value-of select="."/>,</xsl:otherwise>
    </xsl:choose>
   </xsl:for-each>
  </xsl:variable>
  <xsl:value-of select="translate(normalize-space(
                        translate($result,'-',' ')),' ','-')"/>
 </xsl:template>
</xsl:stylesheet>

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

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


Current Thread