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

Subject: RE: Re: [xsl] xsl:analyze-string explanation needed
From: cknell@xxxxxxxxxx
Date: Thu, 20 Jul 2006 09:49:20 -0400
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@xxxxxxxxxx - email



-----Original Message-----
From:     David Carlisle <davidc@xxxxxxxxx>
Sent:     Thu, 20 Jul 2006 14:39:16 +0100
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
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

Current Thread