XSLT regexp?

M

Mark Johnson

Is there a shorthand for this:

<xsl:when test="$day2[.='1'] or $day2[.='2'] or $day2[.='3']">
 
M

Mark Johnson

Martin Honnen said:
Mark Johnson wrote:
Is there a shorthand for this:
<xsl:when test="$day2[.='1'] or $day2[.='2'] or $day2[.='3']">
Your subject line asks for regexp support

Patterns, such as you'd find in regexp. Otherwise, I have to
separately test against all 9 digits to see if a field is a base-10
symbol, not incl. 0. Too bad there isn't a shorthand, for it.

The alternative, of course, is just to run out to a msxml call, and
use regexp in the jscript. But . .

that doesn't exist in XPath
1.0 respectively XSLT 1.0.
XPath 2.0 introduces that, see
http://www.w3.org/TR/xquery-operators/#string.match

A FEB 2004 working draft? I can assume msxml does yet include all of
these interesting functions?
 
M

Martin Honnen

Mark said:
A FEB 2004 working draft? I can assume msxml does yet include all of
these interesting functions?

MSXML 3 and 4 implement XPath 1.0 and XSLT 1.0, I don't know whether MS
has any plans to update MSXML at all to cover newer standards, it could
well be that only .NET is going to cover the newer standards. I think
..NET 2.0 has some XQuery support but it is not yet publically available.
 
K

Klaus-Georg Adams

Mark Johnson said:
Is there a shorthand for this:

<xsl:when test="$day2[.='1'] or $day2[.='2'] or $day2[.='3']">

How about this?

<xsl:when test="contains('123', string($day2))">

There's not really enough context to see what $day2 is, but in XSLT
1.0 it can only be a Result Tree Fragment (see
http://www.w3.org/TR/xslt#section-Result-Tree-Fragments) on which it
is not permitted to use the [] operator. So your code is not
conforming to XSLT 1.0 anyways. I believe you code should be:

<xsl:when test="$day2='1' or $day2='2' or $day2='3'">

in order to conform to XSLT 1.0.

You might want to take a look at the book "XSLT and XPath On The Edge"
by Jeni Tennison. She lists lots of goodies in XPath and XSLT.

Regards, kga
 
J

Janwillem Borleffs

Mark said:
Is there a shorthand for this:

<xsl:when test="$day2[.='1'] or $day2[.='2'] or $day2[.='3']">

<xsl:when test="$test2[.&gt;=1 and .&lt;=3]">

Off topic because you seem to use MSXML, but transformers like Xalan offer a
simple way to implement regular expressions from Java packages like Jakarta
ORO by defining a name space, e.g.:

<xsl:stylesheet
...
xmlns:regex="xalan://com.company.RegExpWrapper">

Which can be applied in the stylesheet as follows:

<xsl:if test="regex:testExp('^\d+$', '0123456789')">
<xsl:text>Match</xsl:text>
</xsl:if>

Where testExp is a method in the RegExpWrapper class.


JW
 
M

Mark Johnson

Janwillem Borleffs said:
Mark said:
Is there a shorthand for this:
<xsl:when test="$day2[.='1'] or $day2[.='2'] or $day2[.='3']">
<xsl:when test="$test2[.&gt;=1 and .&lt;=3]">

Yes, that would be it. When one sees it, it's - d'uh!

Off topic because you seem to use MSXML, but transformers like Xalan offer a
simple way to implement regular expressions from Java packages like Jakarta
ORO by defining a name space, e.g.:


Which can be applied in the stylesheet as follows:
<xsl:if test="regex:testExp('^\d+$', '0123456789')">
<xsl:text>Match</xsl:text>
</xsl:if>
Where testExp is a method in the RegExpWrapper class.

That is more direct and neater than an msxml call. But I do have
regexp in msxml calls. It's not that complicated. But it is integrated
directly into Microsoft office and suite. You can use loadxml and
transform right in VB or whatever code, which many need to do.

How would run load and transform, in Visual Basic, using Xalan? Would
have to save the xml, first, as a file, and then call some
'wrapper'/cover module to transform?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top