xsl-list
[Top] [All Lists]

Re: [xsl] how with xPath 1

2012-04-14 16:14:54
At 2012-04-14 22:03 +0200, Leo Studer wrote:
Hi Ken

thank you for your lines.

The question came up in class. I teach xPath and asked the students how to retrieve the first CD of each artist.
Here the xPath 1 which does the job:
        //cd[not(artist = preceding-sibling::cd/artist)]

A student asked how to retrieve the newest CD of each artist.
I told the student, that I know how to do that with xPath 2.0 and gave this solution for $i in distinct-values(//artist) return (//cd[artist eq $i and year= max(//cd[artist eq $i ]/year)])

The problem is, that in xPath 1 we have neither "for" nor "distinct-values()". So I wonder, is it possible to retrieve the newest cd of each artist with xPath 1 only.

Your proposition with XSLT 1 is nice, thank you.

Forgive me ... when I saw "XPath 1" in the subject line, my thought was that the only context of using XPath 1 is in XSLT 1 and so created an example using XSLT.

I wondered about current(), but that is like key() as it is only in XSLT and not XPath. And even with it I could not figure out how to get what you want because I end up at cdcatalog and not cd.

I cannot think of a way of getting the newest CD of each artist using only XPath 1. This is because of not being able to access information from within the predicate to something known outside of the step. One needs simultaneous comparisons to two children of the element and each time I write the predicate I only have access to one.

Interesting task!

. . . . . . . . . Ken





--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- May 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--