[xquery-talk] xpath1 text node contains attribute, equivalent in xpath2
Misztur, Chris
CMisztur at macleanfogg.com
Fri Dec 27 11:05:44 PST 2013
Oh I see what you're trying to do...
xquery version "3.0";
let $bookstore :=
<bookstore>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
<book category="XML">
<title>Best XML book</title>
<author>you</author>
<year>2014</year>
<price>1.00</price>
</book>
</bookstore>
let $my-book := $bookstore/book[contains(./title/text(), "Learning")]
(: this works too :)
(: let $my-book := $bookstore/book/title[contains(./text(), "Learning")]/.. :)
(: let $my-book := $bookstore/book/title[contains(./text(), "Learning")]/parent::* :)
(: return <p>{string-join($my-book/string(), codepoints-to-string(10))}</p> :)
return
element table
{
for $element in $my-book/child::*
return
element tr
{
element td { local-name($element)||':' },
element td { $element/text() }
}
}
-----Original Message-----
From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of e-letter
Sent: Friday, December 27, 2013 3:20 AM
To: talk at x-query.com
Subject: [xquery-talk] xpath1 text node contains attribute, equivalent in xpath2
Readers,
For an xml file:
...
<book
category="WEB"
>
<title
lang="en"
>
Learning XML
</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
...
An xquery file was created and processed using jedit xml plugins:
<html>
<body>
<p>
{
let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'XML')]/parent::*
return $x
}
</p>
</body>
</html>
Xpath1 specification § 4.2 string functions
(http://www.w3.org/TR/xpath/#section-String-Functions) describes a "contains" function, but this was not found in xpath2; what is the equivalent function in xpath2 please?
The resultant output:
<html>
<body>
<p>
<book category="WEB">
<title lang="en">
Learning XML
</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</p>
</body>
</html>
Is it possible to remove the xml elements from the output file?
An alternative xquery was attempted:
...<p>
{
let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title/text()
return $x
}
</p>...
Resultant output:
...<p>
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
</p>...
Is it possible to select a specific title text with this xquery syntax?
_______________________________________________
talk at x-query.com
http://x-query.com/mailman/listinfo/talk
________________________________
The contents of this message may be privileged and confidential. Therefore, if this message has been received in error, please delete it without reading it. Your receipt of this message is not intended to waive any applicable privilege. Please do not disseminate this message without the permission of the author.
Please consider the environment before printing this e-mail
More information about the talk
mailing list