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

Can I use variables in location paths?

Subject: Can I use variables in location paths?
From: "Chris Ward" <cward@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 27 May 2003 14:09:02 +0100
use variables in xml
Hi,

I'm quite new to XSL and seem to have run into a brick
wall already.  I've checked the archive but can't find 
my question covered (which makes me think I'm asking a
daft question).

Given an XML document, I want to access bits of it based
on the values of variables (ideally parameters to the XSL).


Example XML
===========

  <PositionFactorLevels>
    <Scenario Name="BASECASE">
      <Factor Name="AVERAGE BORROW RATE">
        <Data Date="20030404">1.5000</Data>
        <Data Date="20030407">1.5000</Data>
        <Data Date="20030408">1.5000</Data>
        <Data Date="20030409">1.5000</Data>
        <Data Date="20030410">1.5000</Data>
      </Factor>
      <Factor Name="CLOSING POSITION">
        <Data Date="20030404">-3000000.0000</Data>
        <Data Date="20030407">-3000000.0000</Data>
        <Data Date="20030408">-3000000.0000</Data>
        <Data Date="20030409">-3000000.0000</Data>
        <Data Date="20030410">-3000000.0000</Data>
      </Factor>
      <Factor Name="MONETARY POSITION">
        <Data Date="20030404">-3000000.0000</Data>
        <Data Date="20030407">-3000000.0000</Data>
        <Data Date="20030408">-3000000.0000</Data>
        <Data Date="20030409">-3000000.0000</Data>
        <Data Date="20030410">-3000000.0000</Data>
      </Factor>
    </Scenario>
  </PositionFactorLevels>

XSL (simplified obviously)
===

Using *explicit* string values for the attributes of the data elements I want...

		<xsl:for-each select="PositionFactorLevels/Scenario[ @Name='BASECASE' ]/Factor/Data[ @Date='20030408' ]">
				<xsl:value-of select="../@Name" /> = <xsl:value-of select="." /> <br></br>
		</xsl:for-each>	


Results
	AVERAGE BORROW RATE = 1.5000
	CLOSING POSITION = -3000000.0000
	MONETARY POSITION = -3000000.0000


What I'd like to do is this (note use of variable)
		

		<xsl:variable name="Scenario">BASECASE</xsl:variable>
		<xsl:variable name="Date">20030408</xsl:variable>

		<xsl:for-each select="PositionFactorLevels/Scenario[ @Name='${Scenario}' ]/Factor/Data[ @Date= '${Date}' ]">
				<xsl:value-of select="../@Name" /> = <xsl:value-of select="." /> <br></br>
		</xsl:for-each>			


Am I missing something vital here?  Is it not taking the string value
of the variable as I assume?

I would have assumed a lot of XSL applications need to do this sort of thing.
I basically want subsets of a document based on user-supplied parameter values.

Any help on this would be much appreciated.

Regards,
Chris Ward








 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.