xsl-list
[Top] [All Lists]

RE: Re: [xsl] xsl:analyze-string explanation needed

2006-07-20 06:49:39
I'm not following you. When you say "... match (or not) the whole string ...", 
are you saying that I should change the regex so that it matches the entire 
input string rather than the part I'm interested in, or will adding the "$" 
cause xsl:analyze-string to deal only with the part I'm interested in using?

I've come up with a solution that feels bulky, but it works. Of course, if I 
could slim it down, I'd be so much the happier.

Bulky Solution:
<xsl:template name="extract-minutes-as-seconds">
  <xsl:param name="time" />
  <xsl:variable name="seconds">
          <xsl:analyze-string select="$time" regex="([0-9]+ minutes)">
                <xsl:matching-substring>
                        <xsl:value-of select="60 * 
xs:integer((substring-before(regex-group(1),' minutes')))" />
                </xsl:matching-substring>
          </xsl:analyze-string>
        </xsl:variable>
        <xsl:choose>
                <xsl:when test="$seconds=''"></xsl:when>
                <xsl:otherwise><xsl:value-of select="$seconds" 
/></xsl:otherwise>
        </xsl:choose>
</xsl:template>

-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
Sent:     Thu, 20 Jul 2006 14:39:16 +0100
To:       xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:  Re: [xsl] xsl:analyze-string explanation needed



Can someone explain the operation of this element and how I can get
the output of either one OR the other branch, but not both? 

make the regex match (or not) the whole string (by adding .*$ to the end of the
regex), and if there is a possibility that the string takes more than one
line, setting the flags to make sure . includes the newline character)

David

--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--