Sebastian said:
XPath 2.0 does know regular expressions, doesn't it?
Yes, but it is still under development, consider mention the XPath
version you are asking about.
I want to find nodes. Instead of using =, >, < I want to match with a
regex. But I do not know how the xpath with regex looks like. I looked
in the spec, but I can't understand it. Any examples out there?
The only implementation of the latest XPath 2.0 spec I know is Saxon,
with Saxon 7.8 the matches function of XPath 2.0 is supported, it takes
a string value to check against a second string value which is a regular
expression pattern and returns a boolean.
Here is a simple example XSLT 2.0 stylesheet which uses the matches
function:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:fn="
http://www.w3.org/2003/11/xpath-functions">
<xsl
utput method="xml" indent="yes" />
<xsl:template match="/">
<result>
<xsl:for-each select="('1234', 'abc')">
<match><xsl:value-of select="fn:matches(., '\d{4}')" /></match>
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>
To keep things simple to just demonstrate the use of the matches
function the XSLT doesn't read any nodes from an input XML file so it
doesn't matter against which XML you apply it, when applying it to
itself with Saxon 7.8 from the command line as follows
java -jar C:\Programme\saxon78\saxon7.jar test20040217Xsl.xml
test20040217Xsl.xml
the output is
<?xml version="1.0" encoding="UTF-8"?>
<result xmlns:fn="
http://www.w3.org/2003/11/xpath-functions">
<match>true</match>
<match>false</match>
</result>