RE: [xsl] Reformatting

Subject: RE: [xsl] Reformatting
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Fri, 11 May 2001 08:50:14 +0100
> That said, I transform the XML into HTML by simply using:
>
>     <xsl:template match="ch">
>       <xsl:apply-templates/>,
>     </xsl:template>
>
> to produce:
>
>      1,2,3,4,10,11,12,13,24
>
> I am trying to use XSLT format the output abbreviating ranges
> of channels.
> The above would ideally be formatted as:
>
>       1-4,10-13,24
>
Suggestion: write a set of template rules with different priorities that
compare the value with preceding or following siblings, eg.

<xsl:template match="ch[.=preceding-sibling::ch[1]+1]" priority="2">

if value is one more than previous and one less than next, do nothing
if value is one more than previous and not one less than next, output "-x,"
if value is not one more than previous and not one less than next, output
"x,"
otherwise output "x".

Not tested, may need refining.

Or you could do the same logic in xsl:choose, of course.

Mike Kay
Software AG


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


Current Thread