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

Re: tokenizing and counting with xsl:analyze-string

Subject: Re: tokenizing and counting with xsl:analyze-string
From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 17 Oct 2020 10:38:41 -0000
Re:  tokenizing and counting with xsl:analyze-string
On Sat, Oct 17, 2020 at 2:44 PM Michael Kay mike@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> You can construct a sequence of booleans, in which case you should use
> <xsl:sequence select="true()"/> in place of <xsl:value-of select="1"/>, and
> then you can use `count($temp_result[.])` and `count($temp_result[not(.)]`
> to count the number of true and false items respectively.

Thanks. I'm happy with this.

> If you want to construct the variable as a single string, you can use
> xsl:value-of as I suggested, but then you must declare the variable
> as="xs:string".

Looks like, its not possible to write the XSLT solution for my use case
with this way. Below is my attempt to trying do this,

<xsl:stylesheet version="3.0" xmlns:xsl="

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="/">
      <xsl:variable name="temp_result" as="xs:string">
                <xsl:value-of select="1"/>
        <xsl:value-of select="0"/>
         <xsl:value-of select="count($temp_result)"/>


With above, the XSLT 3.0 processor presents me with following error,

Type error at char 0 in expression in xsl:analyze-string/@select on line 10
column 50 of anl_str_2.xsl:
  XTTE0570  A sequence of more than one item is not allowed as the value of
  $temp_result ("0", "1")
  In template rule with match="/" on line 7 of anl_str_2.xsl
A sequence of more than one item is not allowed as the value of variable
$temp_result ("0", "1")

I think that, as per XSLT 3.0 spec, the child content model
of xsl:matching-substring / xsl:non-matching-substring is a sequence
constructor, which would not allow xsl:analyze-string to return an atomic
value (except in a case, when the returned sequence's size is one).

Mukul Gandhi

Current Thread


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.
First Name
Last Name
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.