This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Regex string function question
Random thoughts :
<aaa>
<bbb>123</bbb>
<bbb>ZYX</bbb>
<ccc>123</ccc>
<date-time>a nice time was 2001-01-24T09:20:25<date-time>
</aaa>
Select all nodes containing a number :
<xsl:apply-templates select="//*[match-regexp(.,'\d')]"/>
=======================================================
All nodes with names starting with b or c:
<xsl:apply-templates
select="//*[match-regexp(name(),'\A[bc]')]"/>
===============================================================
Text nodes creation:
<xsl:apply-templates
select="create-text-nodes-regexp(//date-time,'\s+(\d{4})-(\d{2})-(\d{2})T')"
mode= "format-date" />
<xsl:template match="text()" mode="format-date">
...
<xsl:when test="position()=1">Year: <xsl:value-of
select="."/></xsl:when>
<xsl:when test="position()=2">Month: <xsl:value-of
select="."/></xsl:when>
<xsl:when test="position()=3">Day: <xsl:value-of
select="."/></xsl:when>
Every word character from a string change to a text node if followed by
non-word character:
<xsl:apply-templates select="create-text-nodes-regexp('Hello, world! How
are you?','(\w)\W')"/>
Eric van der Vlist wrote:
>
> Nic,
>
> Miloslav Nic wrote:
> >
> > If it had my dream would come true.
> > But unfortunately they do not appear in XSLT 1.1 proposal.
> > What a pity.
>
> It's also one of my dreams and I am sure we are not the only ones.
>
> Why won't us put a prosal for a standardised extension ?
>
> More precisly, my dream takes the form of functions taking a string (or
> a XPath expression ?) and a regular expression as parameters and
> returning a node set with the results.
>
> Borowing an exemple from the PHP manual [1]:
>
> preg_match_all("Call 555-1212 or 1-800-555-1212 or (612) 555-1313",
> "/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x")
>
> would return a nodeset whose structure could be:
>
> <matches> <!-- maybe we don't need a document element here ? -->
> <match>
> <part>555-1212</part>
> </match>
> <match>
> <part>1-800-555-1212</part>
> </match>
> <match>
> <part>(612) 555-1313</part>
> </match>
> </matches>
>
> What do you think ?
>
> Eric
>
> [1] http://www.php.net/manual/en/function.preg-match-all.php
>
> > --
> > ******************************************
> > <firstName> Miloslav </firstName>
> > <surname> Nic </surname>
> >
> > <mail> nicmila@idoox.com </mail>
> > <support> http://www.zvon.org </support>
> > <zvonMailingList>
> > http://www.zvon.org/index.php?nav_id=4
> > </zvonMailingList>
> --
> ------------------------------------------------------------------------
> Eric van der Vlist Dyomedea http://dyomedea.com
> http://xmlfr.org http://4xt.org http://ducotede.com
> ------------------------------------------------------------------------
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--
******************************************
<firstName> Miloslav </firstName>
<surname> Nic </surname>
<mail> nicmila@idoox.com </mail>
<support> http://www.zvon.org </support>
<zvonMailingList>
http://www.zvon.org/index.php?nav_id=4
</zvonMailingList>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list