Re: [xsl] Creating a padded sort key: easier from elt sequence or string?

Subject: Re: [xsl] Creating a padded sort key: easier from elt sequence or string?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 25 Jul 2006 11:05:19 +0100
> 2) an element containing a sequence of PCDATA elements, one for each of 
> the numbers and letters (the dot in between may be added during
> processing)

This format is the easiest to handle in xslt as it's always better at
dealing with data that's fully marked up rather than parsing short
strings.

But parsing 3.11.A.9 in xslt1 isn't difficult with a recursive template
using substring-before (or probably you'll find a ready written template 
on the web somewhere) or you could use an extension function like
saxon:tokenize

> Would the solution differ much in XSLT 2.0?
not ifyou  used an element for each segment, but if you are parsing 3.11.A.9
then xslt2 solution would be completely different as you can tokenize to
a list of strings and then format each string, specifically


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


  <xsl:template name="main">
    <xsl:for-each select="
'1.2.3',
'19.A.B.444',
'x.y.z'
">
:  <xsl:sequence select="string-join(
      for $t in tokenize(.,'\.') return 
        (if (matches($t,'[0-9]')) then format-number(number($t),'000') else $t),
      '.')"/>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>


$ saxon8 -it main  pad.xsl
<?xml version="1.0" encoding="UTF-8"?>
:  001.002.003
:  019.A.B.444
:  x.y.z

Current Thread