On 10/24/06, Philip Vallone <philip(_dot_)vallone(_at_)verizon(_dot_)net> wrote:
Hello Everyone,
I have numerous xml documents that have content that refers to US code of
Federal Regulations (CFRs) e.g.
'GENERAL [§21.197]' or 'PERMIT [§21.197 & §21.199]'
Is there a simple string function that extracts integers from a string?
I am trying to use a series of functions to do the same. e.g.
<xsl:for-each-group select="//Title" group-by=".">
<xsl:if test="contains(., '§')">
<xsl:variable name="before"
select="substring-after(.,'[')"/>
<xsl:variable name="after"
select="substring-before($before,']')"/>
<xsl:variable name="removespace" select="tokenize($after,
'&')"/>
<xsl:value-of select="$removespace"/>
p/>
</xsl:if>
</xsl:for-each-group>
Which produces:
§21.197
§21.197 §21.199
Desired result:
21.197
21.197
21.199
I will eventually group and sort by number.
How about:
<xsl:variable name="numbers" as="xs:string*">
<xsl:analyze-string select="//Title" regex="\d+\.?\d*">
<xsl:matching-substring>
<xsl:sequence select="."/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:for-each-group select="$numbers" group-by=".">
<xsl:sort select="current-grouping-key()"/>
<xsl:sequence select="."/>
</xsl:for-each-group>
You might want to tight up the regex a little to not allow "2." for example...
cheers
andrew
--~------------------------------------------------------------------
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>
--~--