Re: [xsl] tokenizing and counting with xsl:analyze-string

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

> No, that's not correct. A sequence constructor can return anything. For
> example if the sequence constructor is
>
> <xsl:sequence select="1 to 5"/>
>
> then the value is a sequence of five integers. The containing instruction
> might turn this into something else (e.g. a text node), but most
> instructions, like xsl:choose or xsl:analyze-string, will leave it
> untouched.
>

Thanks for the explanation.

I think that, I'm finally able to write an XSLT solution, the way you
suggested earlier (i.e, using string-length(translate( ... to compute the
count). Below is my attempt, that seems to work fine,

<xsl:stylesheet version="3.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform";
                                               xmlns:xs="
http://www.w3.org/2001/XMLSchema";
                                               exclude-result-prefixes="xs">

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

   <xsl:template match="/">
      <xsl:variable name="temp_result">
          <xsl:analyze-string
select="'abhello1cdehello2fghijklhello3hello4mhello5nhello6'"
                                         regex="hello[1-9]">
             <xsl:matching-substring>
                <xsl:value-of select="1"/>
             </xsl:matching-substring>
             <xsl:non-matching-substring>
        <xsl:value-of select="0"/>
             </xsl:non-matching-substring>
          </xsl:analyze-string>
      </xsl:variable>
      <result>
<yes count="{string-length(translate($temp_result, '0', ''))}"/>
<no count="{string-length(translate($temp_result, '1', ''))}"/>
      </result>
   </xsl:template>

</xsl:stylesheet>

With above mentioned XSLT stylesheet, the thing that worked is, not
explicitly declaring the type for xsl:variable name="temp_result".



-- 
Regards,
Mukul Gandhi

Current Thread