This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Newbie to XSLT
- To: xsl-list at mulberrytech dot com
- Subject: Re: Newbie to XSLT
- From: Steve Tinney <stinney at sas dot upenn dot edu>
- Date: Wed, 09 Feb 2000 09:46:00 -0500
- References: <003c01bf7304$0593d0e0$5461a8c0@tektools.com>
- Reply-To: xsl-list at mulberrytech dot com
> So to find out what size John's cubicle is,
>
> 1. I need to go to the 3rd "instance" node, ( type is "Association"
> )
> 2. look up the relationship between John's PC and where his location
> is ( Cube 47 )
> 3. Go back to 2nd "instance" node ( name is "location" ), and get the
> size.
>
> Note that there could be multiple PC's and Location's in the same XML
> document.
>
> From my basic knowledge of XSLT, I felt that doing this using a
> stylesheet would not be possible. So I was thinking of using the DOM
> tree and using XPath to do this.
>
> I want to know from the XSL gurus, if this can be done using a XSL
> stylesheet. ( Basically, how do we store the "Cube 47" value in a
> variable, then use it to go back through the document and look for the
> size for "Cube 47" ??? )
There is nothing here that cannot be done with XSLT (which is in some
sense a superset of XPath).
To store a value in a variable, use xsl:variable. To reference it
later, prefix the name with '$'. To navigate around the document use
location steps and predicates. See the XPath and XSLT specs and the XSL
FAQ for further information.
For example, you could do something like this, although it does not
function in the same way as you put it in the question:
<xsl:variable name="cube" select="/*/instance[@type='Association']
/reference[@dependent='location']
/value"/>
<xsl:variable name="size" select="/*/instance
[@name='location'][value=$cube]
/size"/>
You can even do all this without variables by using the current()
function.
Steve
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list