Subject: [xsl] keys across multiple children From: "Ahmad J. Reeves" <ahmad@xxxxxxxxxxxxxx> Date: Tue, 05 Feb 2002 09:37:32 +0000 |
Hi, I'm trying to get to grips with the syntax of keys across children with different names. (I can get the keys to work if the names are the same) With the following xml:- <FILES> <RECORDA> <id>13</id><name>Fred</name><project_name>Building</project_name> </RECORDA> <RECORDB> <id>14</id><name>Fred</name><project_name>Looking</project_name> </RECORDB> <RECORDC> <id>15</id><name>Harry</name><project_name>Writing</project_name> </RECORDC> </FILES> I'm trying to display the customer name once with a list of projects. I can get this to work if all of the child nodes of <FILES> have the same name, e.g. <RECORD>. If however I change them to three different names, I need to provide alternatives to the key select as below:- <?xml version="1.0"?> <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:key name="rows" match="RECORDA | RECORDB | RECORDC" use="name"/> <xsl:variable name="newline"> <xsl:text> </xsl:text> </xsl:variable> <xsl:template match="FILES"> <xsl:apply-templates select="RECORDA[generate-id(.)=generate-id(key('rows', name)[1])]"/> </xsl:template> <xsl:template match="FILES/*"> <xsl:value-of select="name"/> <xsl:for-each select="key('rows',name)"> <xsl:value-of select="$newline"/> <xsl:value-of select="project_name"/> <xsl:value-of select="$newline"/> </xsl:for-each> </xsl:template> </xsl:stylesheet> This outputs:- Fred Project 1 Project 2 But no Harry. So its as if it doesn't include RECORDC in the key list. q1. Whats wrong with the stylesheet that it doesnt do this. I think its :- select="RECORDA[generate-id(. but every other path I try ends up with no output. q2. Does the vertical bar | mean 'or', and wouldnt it be better to use ',' which I think means 'and'? When I tried ',' it threw up loads of exceptions. q.3 If the xml looked like this instead... <FILES> <RECORDA> <id>13</id><name>Fred</name><project_name>Building</project_name> </RECORDA> <RECORDA> <id>14</id><name>Fred</name><project_name>Building</project_name> </RECORDA> <RECORDB> <id>15</id><name>Fred</name><project_name>Looking</project_name> </RECORDB> <RECORDC> <id>16</id><name>Harry</name><project_name>Writing</project_name> </RECORDC> </FILES> How could I get the result to remove multiple copies e.g. to output <id>13</id> but not <id>14</id> Many thanks people, Ahmad ------------------------------------------------- Ahmad J Reeves BSc (Hons) MSc (Dist) PhD Student Information, Media & Communication Research Group Department of Computer Science Queen Mary, University of London E1 4NS Tel +44(0) 207 882 5257 Fax +44(0) 208 980 6533 http://www.dcs.qmw.ac.uk/imc XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: Re: Article: The Function, Dimitre Novatchev | Thread | [xsl] number("2,000") -> NaN, Morten Primdahl |
Re: [xsl] keep properties, Joerg Pietschmann | Date | RE: [xsl] keep properties, DPawson |
Month |