Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Comma separated list using XPath

From: "Dimitre Novatchev" <dimitren@---.---.-->
To: NULL
Date: 12/4/2007 7:24:00 PM

> I put an example below. So I don't know if this is
> going to be possible.  If anyone has any other thoughts, either for
> the first problem as an intellectual exercise, or to the 'revised'
> situation--including using XSLT or XQuery--that'd be great. Otherwise
> thanks for all the input!

Of course, this is possible. Below is one XPath expression the evaluation of 
which produces the wanted result:

    for $name in distinct-values(/*/*/*/author)
      return
         (concat('Books by ', $name, ': ',
           string-join(
                   /Library/Branch/book
                   /(if(author=$name)
                       then concat(position(),
                                   if(following::author[. eq $name])
                                      then ','
                                      else ''
                                   )
                             else ()
                     ),
                     ''
                  ),
           '&#xA;'
          )
         )



When evaluated with the current document the one supplied in your last 
message, the result is:


Books by John: 1,3,5
 Books by Mary: 2,6
 Books by Mark: 4



Cheers,
Dimitre Novatchev


<nikoromano@g...> wrote in message 
news:19b702bd-1661-488d-b7fb-715a8b27172e@d......
> Hi Guys
>
> Thanks for all the input. Dimitre, your suggestion is something I had
> tried as well. Unfortunately I don't think it quite works... Well,
> more specially it *does* work for the one example I posted, but
> imagine if I added another book below the last one with the author
> Mary. (I put an updated XML snippet below) The the output for John is:
> 1, 3, 5,
> (Since the 5th book is no longer the last book overall, a comma is
> added after the 5.)
>
> The reason I am trying to use XPath is I am being forced to use Altova
> StyleVision for this project, and as far as I am aware,  StyleVision
> won't let me do this any other way (i.e. using the XLST or XQuery).
>
> After I posted this, I realized the problem is actually more
> complicated than I had previously thought. The point is actually to
> create a detailed list of books, sorted by title (title is just
> another element inside book) with a summary on top telling which books
> below correspond to the given authors by the position the book appears
> in the report. I put an example below. So I don't know if this is
> going to be possible.  If anyone has any other thoughts, either for
> the first problem as an intellectual exercise, or to the 'revised'
> situation--including using XSLT or XQuery--that'd be great. Otherwise
> thanks for all the input!
>
> Output example
> Books by John: 1, 2, 5
> Books by Mary: 3, 6
> Books by Mark: 4
>
> Book 1:
> Title: A Book Title Starting With 'A'
> Author: John
>
> Book 2:
> Title: Books Are Fun!
> Author: John
>
> Book 3:
> Title: Can You Tell Me How To Get To Sesame Street?
> Author Mary
> ...
>
>
>
> XML Example
> <?xml version="1.0" encoding="UTF-8"?>
> <Library>
> <Branch>
> <book>
> <author>John</author>
> </book>
> <book>
> <author>Mary</author>
> </book>
> </Branch>
> <Branch>
> <book>
> <author>John</author>
> </book>
> <book>
> <author>Mark</author>
> </book>
> <book>
> <author>John</author>
> </book>
> <book>
> <author>Mary</author>
> </book>
> </Branch>
> </Library>
>
>
> On Dec 2, 10:26 pm, "Dimitre Novatchev" <dimit...@tpg.com.au> wrote:
>> "Joe Kesselman" <keshlam-nos...@comcast.net> wrote in message
>>
>> news:gqmdnXmD4cUuFszanZ2dnUVZ_tLinZ2d@c......
>>
>> >>           /(if(author='John')
>>
>> > I believe if/then/else expressions require XPath 2.0 or XQuery. If 
>> > that's
>> > what you have available, go for it;
>>
>> Yes, this was the code in the OP first post.
>>
>> Cheers,
>> Dimitre Novatchev
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent