[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Reformatting

Subject: Re: Reformatting
From: Dan Diebolt <dandiebolt@xxxxxxxxx>
Date: Thu, 10 May 2001 21:11:46 -0700 (PDT)
reformatting p3
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
  • Reformatting
    • Brucato, Greg - Thu, 10 May 2001 19:03:37 -0400 (EDT)
      • <Possible follow-ups>
      • Dan Diebolt - Fri, 11 May 2001 00:10:30 -0400 (EDT) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.