Subject: Re[2]: [xsl] finding position() of an element in a different context From: Kevin Burges <xmldude@xxxxxxxxxxxxxxxx> Date: Thu, 3 May 2001 11:35:18 +0100 |
Hi Jeni, JT> Hi Kevin, >> I've remembered another part of the problem. Look at the structure >> again: >> >> <top> >> <visits> >> <visit id="visit1Name"/> >> <visit id="visit2Name"/> >> </visits> >> <formtypes> >> <formtype id="formtype1Name"/> >> <formtype id="formtype2Name"/> >> </visits> >> <forms> >> <form visit="visit1Name" formtype="formtype1Name"/> >> <form visit="visit1Name" formtype="formtype2Name"/> >> <form visit="visit2Name" formtype="formtype2Name"/> >> </forms> >> </top> >> >> Am I not right in saying that if I am in the context of a <visit> >> element, doing: >> >> <xsl:variable name="matchingForm" >> select="//forms/form[(@formtypeID = $formtypeID) and (@visitID = >> $visitID)]"/> >> >> will not work, because "//forms" is taken relative to the context >> node? Certainly this seems to be happening, as no matches are >> occurring. JT> So //forms gets all forms elements in the document. In JT> fact you just want: JT> /top/forms JT> since there's only one forms element that you're actually interested JT> in and you know where that is. actually this is not quite the case ( I was simplifying in the previous example), there could be form emelents in various places. The match I am actually looking for is //sequential//form as I could have ... <sequential> <forms> <start> <form ....... /> <form ....... /> </start> <form ........ /> <form ........ /> <end> <form ....... /> <form ....... /> </end> </forms> </sequential> ... JT> The reason your XPath won't work is that you're looking for a JT> 'formtypeID' attribute and a 'visitID' attribute on each form element, JT> whereas the attributes that are there are called 'formtype' and JT> 'visit'. again sorry, that was just a typo. JT> You might also be interested in using a key to retrieve the relevant JT> form. You could create a key that uses both the visit and the JT> formtype to index the form elements: JT> <xsl:key name="forms" JT> match="form" JT> use="concat(@formtype, ':', @visit)" /> JT> You can then retrieve the relevant form with: JT> key('forms', concat($formtypeID, ':', $visitID)) This sounds promising, so I tried it. At first it again did not work. While testing I noticed that I was setting variables as follows: <xsl:variable name="formtypeID"><xsl:value-of select="@id"/></xsl:variable> When I change this to: <xsl:variable name="formtypeID" select="@id"/> Everything started working fine. Is the first returning the text value of @id, while the second is actually returning the attribute node itself or something?? -- groovy baby, Kevin mailto:xmldude@xxxxxxxxxxxxxxxx +++++++++++++ Cool music - http://mp3.com/marshan ++ Attitude Rock Webzine - http://burieddreams.com/attitude XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re[4]: [xsl] finding position() of , Kevin Burges | Thread | Re: [xsl] finding position() of an , David Carlisle |
Re: [xsl] RE: [xsl] Handling of spe, David Carlisle | Date | [xsl] Random Number Gen, Steve Renshaw |
Month |