[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re[2]: finding position() of an element in a different

Subject: Re[2]: finding position() of an element in a different context
From: Kevin Burges <xmldude@xxxxxxxxxxxxxxxx>
Date: Thu, 3 May 2001 11:35:18 +0100
form element position
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.