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

Re: [xsl] analyze-string help?

Subject: Re: [xsl] analyze-string help?
From: Dan Vint <dvint@xxxxxxxxx>
Date: Sun, 10 Jun 2012 09:01:49 -0700

At 11:46 PM 6/9/2012, you wrote:
You show the output as having a newline between "Module" and
"Batteries" (which might just be an artifact of e-mail) -- is that
what the input has? If so, your input pattern doesn't match newline,
and will fail. To fix, just use normalize-space($title) as the input
(i.e., value of @select).

>>>The content I'm parsing is machine generated, so no carriage return.

But is there any reason not to use a simpler regex? E.g.,
  <xsl:analyze-string select="normalize-space($title)" regex="(.+) - (.+)">

Even if it doesn't fix your problem, it might make it easier to find.

>>>I was being a little lazy, I had copied this pattern match from another one I was using, in it I was having to match just on ascii characters and numbers. I had a comment in the stylesheet that I needed to fix the pattern to be more general as other chaacters could show up. This modification should handle that problem.


> I have the following value in the $title variable without the
> quotes "foo-119 Mode Module Batteries - Installation"
> I have a series of strings like this where I want to separate the
> content after the last "space dash space" from everything the
> proceeds that point. So I came up with the following:
> <xsl:analyze-string select="$title" regex="([A-Za-z0-9 -,./]*) - ([
> A-Za-z0-9/]*)">
>        <xsl:matching-substring>
>              <techname><xsl:value-of select="regex-group(1)"/></techname>
>              <infoname><xsl:value-of select="regex-group(2)"/></infoname>
>       </xsl:matching-substring>
>       <xsl:non-matching-substring>
>              <xsl:comment>NO MATCH for techname and infoname
> "<xsl:value-of select="$title"/>"</xsl:comment>
>       </xsl:non-matching-substring>
> </xsl:analyze-string>
> I'm getting this output:
>          <!--NO MATCH for techname and infoname "foo-119 Mode Module
> Batteries - Installation"-->
> <techname>119 Mode Module Batteries</techname>
> <infoname>Installation</infoname>
> I was expecting all dashes to be captured except for the last one
> or at least the first "space dash space", it looks like the pattern
> gets the "foo-" and flags it as mismatched and then captures the
> other two strings. Can you help me understand what is going on.

--------------------------------------------------------------------------- Danny Vint

Panoramic Photography

voice: 619-938-3610

Current Thread