xsl-list
[Top] [All Lists]

Re: [xsl] analyze-string help?

2012-06-10 07:58:46
Dan,

Assuming that both the tech name as well as the info name might use the 
space-dash-space string, I would first split the string and then act on 
depending on the number of tokens:

<xsl:variable name="tokens" select="tokenize($title, ' - ')"/>
<xsl:choose>
  <xsl:when test="count($tokens) gt 2">
    <xsl:message select="'something unexpected: too many tokens'"/>
  </
  <xsl:when test="count($tokens) eq 2">
    <techname><xsl:value-of select="$tokens[1]"/></techname>
    <infoname><xsl:value-of select="$tokens[2]"/></infoname>
  </
  <xsl:otherwise>
    <!-- maybe handle the default action -->
  </
</

- Michael

Am 10.06.2012 um 07:40 schrieb Dan Vint:

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.

thanks
..dan





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


<Prev in Thread] Current Thread [Next in Thread>