|
Subject: Re: [xsl] how with xPath 1 From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 14 Apr 2012 11:53:35 -0400 |
in xPath 2.0 I retrieve the newest CDs for each artist like that
for $i in distinct-values(//artist) return (//cd[artist eq $i and year= max(//cd[artist eq $i ]/year)])
How can I do that with xPath 1?
T:\ftemp>type leo.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<cdcatalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>The Times They Are a-Changin'</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1964</year>
</cd>
<cd>
<title>Faster Than The Speed of Light</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>Columbia</company>
<price>9.90</price>
<year>1983</year>
</cd>
<cd>
<title>Time Out of Mind</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1997</year>
</cd>
</cdcatalog>
T:\ftemp>xslt leo.xml leo.xsl
<?xml version="1.0" encoding="utf-8"?>
For Bonnie Tyler found Hide your heart 1988
For Bob Dylan found Time Out of Mind 1997
T:\ftemp>type leo.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:template match="cdcatalog">
<!--select those in the latest year for each artist-->
<xsl:for-each select="cd[not(year < key('cds-by-artist',artist)/year)]">
<!--report findings-->
<xsl:text>
</xsl:text>
<xsl:value-of select="concat('For ',artist,' found ',title,' ',year)"/>
</xsl:for-each>
</xsl:template>
-- 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@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] how with xPath 1, Leo Studer | Thread | Re: [xsl] how with xPath 1, Leo Studer |
| Re: [xsl] "Tunneling" a parameter i, David Carlisle | Date | Re: [xsl] Summing hours-worked valu, Mark |
| Month |