472,353 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

xpath with regex

Hi group,
please give me an example of a xpath with regex or
better a link with examples.
Thanks in advance,
Sebastian
Jul 20 '05 #1
7 16524


Sebastian Petzelberger wrote:
please give me an example of a xpath with regex or
better a link with examples.


I am not sure what you are looking for here, XPath (1.0 at least)
doesn't know regular expressions, it only has some string functions. In
what context are you using XPath, and why do you need "xpath with regex"?

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
> I am not sure what you are looking for here, XPath (1.0 at least)
doesn't know regular expressions, it only has some string functions.
XPath 2.0 does know regular expressions, doesn't it?
In
what context are you using XPath, and why do you need "xpath with regex"?


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?
Jul 20 '05 #3


Sebastian Petzelberger wrote:
I am not sure what you are looking for here, XPath (1.0 at least)
doesn't know regular expressions, it only has some string functions.

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.
In
what context are you using XPath, and why do you need "xpath with regex"?

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:output 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>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #4
Thank you Martin for your awnser, and for your time so far. Sorry,
that I am replying so late.
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.
Thank you, I will look deeper in this.
Here is a simple example XSLT 2.0 stylesheet which uses the matches
function:
Do I need xslt?
<match><xsl:value-of select="fn:matches(., '\d{4}')" /></match>


fn:matches(., '\d{4}') How will look this function in an xpath?

//CreateOrderResponse/OrderData/BizTalk/@timestamp
is an example xpath, how does the regex function be part of the xpath?

Thanks again, Sebastian
Jul 20 '05 #5
In article <98**************************@posting.google.com >,
Sebastian Petzelberger <Se********************@haenchen.softwarezentrum.d e> wrote:

[Martin wrote]

% > <match><xsl:value-of select="fn:matches(., '\d{4}')" /></match>
%
% fn:matches(., '\d{4}') How will look this function in an xpath?

That _is_ an XPath. It's actually an example of an XPath extension function
-- is this how it's defined in XPath 2.0? You can define something similar
with most or all XPath implementations if you have a perl regular expression
engine in the appropriate language.

% //CreateOrderResponse/OrderData/BizTalk/@timestamp

% is an example xpath, how does the regex function be part of the xpath?

This is actually a location path. Location paths are part of the xpath
language, but they aren't all of it. The question is, what do you
want to do? If you'd like to select timestamps which match some regular
expression, you could have

//CreateOrderResponse/OrderData/BizTalk/@timestamp[fn:matches(., $yourREhere)]

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #6


Sebastian Petzelberger wrote:

Here is a simple example XSLT 2.0 stylesheet which uses the matches
function:

Do I need xslt?


That depends on the tool you use (and your knowledge with that tool), I
know how to use Saxon 7.8 as an XSLT 2.0 processor therefore I have
given an XSLT 2.0 stylesheet making use of XPath 2.0. I think Saxon also
allows you to evaluate pure XPath expressions but without looking deeper
into its documentation I can't give an example on how to do this.
<match><xsl:value-of select="fn:matches(., '\d{4}')" /></match>

fn:matches(., '\d{4}') How will look this function in an xpath?


Well, the value of the select attribute is an XPath expression, and
fn:matches is a function defined in XPath 2.0 (with the prefix fn bound
to the appropriate namespace).
//CreateOrderResponse/OrderData/BizTalk/@timestamp
is an example xpath, how does the regex function be part of the xpath?


//CreateOrderResponse/OrderData/BizTalk/@timestamp[fn:matches(.,
'\d{4}')]
filters all timestamp attribute nodes whose value matches the regular
expression \d{4} (four digits).
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #7
Dear Martin,
//CreateOrderResponse/OrderData/BizTalk/@timestamp[fn:matches(.,
'\d{4}')]
filters all timestamp attribute nodes whose value matches the regular
expression \d{4} (four digits).


Thank you for your solution, that was exactly I was looking for.

Thank you Patrick as well.

Greetings, Sebastian
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context...
4
by: Timo Nentwig | last post by:
Hi! Seems that * cannot stand for non-existing nodes, i.e. /html/*/title will not match <html> <title>won't match</title>
4
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); ...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.