|
Subject: [xsl] Can I use variables in location paths? From: "Chris Ward" <cward@xxxxxxxxxxxxxxxxxxx> Date: Tue, 27 May 2003 14:09:02 +0100 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] wanting to clarify some s, Robert P. J. Day | Thread | Re: [xsl] Can I use variables in lo, David Carlisle |
| RE: [xsl] ampersand fun, Martin Lampen | Date | RE: [xsl] wanting to clarify some s, Jarno . Elovirta |
| Month |