Re: [xsl] Why is 'analyze-string' producing this weird output?

Subject: Re: [xsl] Why is 'analyze-string' producing this weird output?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 23 Aug 2023 13:52:17 -0000
> Your group counting is off

Ah! Spot on.

Thank you David!

/Roger

From: David Carlisle d.p.carlisle@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, August 23, 2023 9:45 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Why is 'analyze-string' producing this weird output?




Your group counting is off (using entities is not helping:-)

<!ENTITY section-num "[0-9]+(\.[0-9]+)+">
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
 B B B B B B B B  ^^^1
<!ENTITY section-name "[A-Z][a-zA-Z /]+">
<!ENTITY paren "\([^\)]+\)">
I use 'analyze-string' to break apart the input:

<xsl:analyze-string select="$line" regex="^(&section-num;) (&section-name;)
(&paren;)$">

B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
 B B B B B B B B B B B B B B B B B B B B B B B B B B B 
^^^1B B B B B B B B B B B B B B B B B B 
^^^3B B B B B B B B B B B B B B B B B B B  ^^^4


David




On Wed, 23 Aug 2023 at 14:40, Roger L Costello mailto:costello@xxxxxxxxx
<mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi Folks,

I'm baffled.

Here is a sample input line:

5.2 Record Type (S/T)

The first part -- 5.2 -- is the 'section number'.

The second part -- Record Type -- is the 'section name'.

The third part -- (S/T) -- is the 'abbreviated name'.

I want the XSLT to generate this:

<header>
B  B  <section-num>5.2</section-num>
B  B  <section-name>Record Type</section-name>
B  B  <abbreviated-name>(S/T)</abbreviated-name>
</header>

I created several ENTITIES for use by my XSLT:

<!ENTITY section-num "[0-9]+(\.[0-9]+)+">
<!ENTITY section-name "[A-Z][a-zA-Z /]+">
<!ENTITY paren "\([^\)]+\)">

I use 'analyze-string' to break apart the input:

<xsl:analyze-string select="$line" regex="^(&section-num;) (&section-name;)
(&paren;)$">
B  B  <xsl:matching-substring>
B  B  B  B  <header>
B  B  B  B  B  B  <section-num><xsl:value-of
select="regex-group(1)"/></section-num>
B  B  B  B  B  B  <section-name><xsl:value-of
select="regex-group(2)"/></section-name>
B  B  B  B  B  B  <abbreviated-name><xsl:value-of
select="regex-group(3)"/></abbreviated-name>
B  B  B  B  </header>
B  B  </xsl:matching-substring>
</xsl:analyze-string>

That produces this erroneous output:

<header>
B  B  <section-num>5.2</section-num>
B  B  <section-name>.2</section-name>
B  B  <abbreviated-name>Record Type</abbreviated-name>
</header>

I am baffled why I am getting that output.

What am I doing wrong, please?

/Roger

http://www.mulberrytech.com/xsl/xsl-list
http://lists.mulberrytech.com/unsub/xsl-list/673357 ()

Current Thread