Subject: Re: [xsl] Seek XPath 2.0 expression for this: Are there any book titles with more than one binding? From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 2 May 2019 13:14:17 -0000 |
At the bottom of this message is my XML document. I need an XPath 2.0expression that returns the result of this query:
binding (hardcover versus softcover).
Are there any book titles with more than one binding? If yes, then show the first book for each binding.
For the below XML document, the query should return these two books:
<Book> <Author>Sally Smith</Author> <Title>XYZ</Title> <Binding>hardcover</Binding> <Count>1</Count> <Description>lo lo lo ..</Description> </Book> <Book> <Author>Sally Smith</Author> <Title>XYZ</Title> <Binding>softcover</Binding> <Count>1</Count> <Description>do do do ..</Description> </Book>
Notice that the two books have the same author and title but different
This XPath 2.0 expression seems to work:
for $i in /Bookstore/BookTitle/Book[1], $j in /Bookstore/BookTitle/Book[1] return if (($i ne $j) and ($i/Author eq $j/Author) and ($i/Title eq $j/Title) and ($i/Binding ne $j/Binding) and ($i = $j/preceding::Book)) then ($i, $j) else ()
That expression seems awfully complicated. Is there a simpler expression? If
there isn't a simpler expression, then do you see anything missing in the expression (i.e., something that the expression doesn't take into consideration)?
That seems more like a job for XSLT or XQuery, if I have grasped the problem correctly then in XQuery it would reduce itself to
for $book in Bookstore/BookTitle/Book[1] group by $author := $book/Author, $title := $book/Title, $binding := $book/binding where tail($book) return $book
As for your XPath, I think that instead of $i ne $j you rather want not($i is $j)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Seek XPath 2.0 expression for, Costello, Roger L. c | Thread | Re: [xsl] Seek XPath 2.0 expression, Michael Kay mike@xxx |
[xsl] Seek XPath 2.0 expression for, Costello, Roger L. c | Date | Re: [xsl] Seek XPath 2.0 expression, Michael Kay mike@xxx |
Month |