This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Regular expression functions (Was: Re: comments on December F&O draft)



> Presumably the match patterns would match the entire string? 

you think I have any idea how it's supposed to work?

Actually no i think not see in my example first the \gamma template
fired then the \sqrt one even though they're in the same string.

<xsl:regexp-template match="([^&#xA;&#x9;&#xD;]*)([&#xA;&#x9;&#xD;])(.*)">
  <xsl:value-of select="$1" />
  <xsl:value-of select="if ($2 = '&#xA;') then '\n'
                        else if ($2 = '&#x9;') then '\t'
                        else if ($2 = '&#xD;') then '\r'" />
  <xsl:apply-regexp-templates-to-string select="$3" />
</xsl:regexp-template>


or just


<xsl:regexp-template match="&#A;">
 <xsl:text>\n</xsl:text>
</xsl:regexp-template>
<xsl:regexp-template match="&#D;">
 <xsl:text>\r</xsl:text>
</xsl:regexp-template>
<xsl:regexp-template match="&#9;">
 <xsl:text>\t</xsl:text>
</xsl:regexp-template>

> The big weakness if this was the *only* method of doing matches is
> that you can't use it with dynamic regular expressions - for example
> match strings that contain the keyword $keyword as a word. Any ideas
> around that one?

Currently template matches don't allow global variables in a (failed)
attempt to prevent circularity, if template matches could have global
variables references then these regexp ones could too. then of course
you'd have to decide if the regexp string attribute was an xpath
expression and so make up the regexp using concat() or whether it is a
string but allow expath expressions such as variable references using
avt {}.

>  occurred to me that this could be useful if, for example, you
> wanted all your numbers to be formatted in the same way throughout the
> document - you could have:

  <xsl:template match="value of type xs:decimal">
    <xsl:value-of select="format-number(., '#,##0.00')" />
  </xsl:template>

but if an element node is schema typed you can presumably go


<xsl:template match="text()[. = cast-to-decimal(.)]">
  <xsl:value-of select="format-number(., '#,##0.00')" />
</xsl:template>

once they decide what the constructor and/or casting function syntax is.
But regexp matches are special in that they really do match into
substrings.


David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]