xsl-list
[Top] [All Lists]

Can I use variables in location paths?

2003-05-27 06:09:02

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



<Prev in Thread] Current Thread [Next in Thread>