[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XPath expression to convert a list of (string) integers into a sequence of (genuine) integers


Subject: Re: [xsl] XPath expression to convert a list of (string) integers into a sequence of (genuine) integers
From: Graydon <graydon@xxxxxxxxx>
Date: Wed, 26 Dec 2012 09:32:23 -0500

On Wed, Dec 26, 2012 at 01:44:31PM +0000, Costello, Roger L. scripsit:
> I want an XPath expression to convert the codepoints in this element
> 
> <Numbers>84 104 101 32 115 101 99 114 101 116 32 97 103 101 110 116 32 105 115 32 46 46 46</Numbers>
> 
> into a string.
> 
> Here is one way to do it
> 
>     codepoints-to-string(for $i in tokenize(., '\s+') return xs:integer($i))
> 
> Is there a better XPath expression? 
> 
> By "better" I mean simpler.

All the type-coercion functions take single operands, not sequences, so I'm pretty
sure that is the simplest way to do it in XPath 2.0.

In XPath 3.0, you can use the "simple map operator", !, to write

codepoints-to-string(tokenize($numbers/Numbers,'\p{Zs}')!xs:integer(.))

Whether you think that's simpler might be a matter of taste, though.

-- Graydon


Current Thread
Keywords