[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Reformatting
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|