[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Variable - Results Tree Fragment Problem


Subject: RE: [xsl] Variable - Results Tree Fragment Problem
From: "Martinez, Brian" <brian.martinez@xxxxxxxxxxx>
Date: Wed, 27 Aug 2003 15:45:16 -0600

> From: Pappa [mailto:anarkin@xxxxxxxxxxxx]
> Sent: Wednesday, August 27, 2003 2:59 PM
> Subject: [xsl] Variable - Results Tree Fragment Problem
> 
> 
> Hi,
> 
> I have a little problem, which I assume is connected with the 
> values I'm 
> after being converted to results tree fragments. I have tried various 
> things, but nothing seems to work. Also, as I'm using Sablotron, I 
> cannot use extensions such as node-set() to solve this problem.
> 
> I'm trying to get the values of all the parameters without 
> referencing 
> each one explicitly.

>         <!-- THIS WAS MY FIRST ATTEMPT AT GETTING THE VALUES OF THE 
> PARAMETERS WITHOUT REFERENCING THEM EXPLICITLY - I GET THE 
> RESULT ', , ' -->
>     
>         <xsl:for-each 
> select='document("this.xsl")/xsl:stylesheet/xsl:param'>
>             <xsl:value-of select='.'/><xsl:if 
> test='position()!=last()'>, </xsl:if>
>         </xsl:for-each>
>         

<xsl:value-of select="@select"/>

This will return the value of the select attribute, but that will not be the
same as the value of the param itself!  For instance, if your param is:

<xsl:param name="p1" select="/document/params/p1"/>

which represents a node-set, then <xsl:value-of select="@select"/> will
output the string '/document/params/p1' and not the node-set indicated by
the expression.  Even if your param is a string:

<xsl:param name="p1" select="'red'"/>

then <xsl:value-of select="@select"/> will return the literal string 'red'
with quotes included--this is NOT equal to <xsl:value-of select="$p1"/>!

Perhaps I'm misinterpreting your question, but it appears that you're
attempting to impose a procedural construct on your stylesheet, for which
XSLT is ill-suited.  Why would you need to loop through stylesheet
parameters?  If it's because the number of parameters may change, then it
would be much easier to create a source document with the input parameters
instead:

<parameters>
  <param name="p1" value="red"/>
  <param name="p2" value="green"/>
  <param name="p3" value="blue"/>
</parameters>

Then your solution becomes much more elegant:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/parameters">
    <xsl:apply-templates select="param"/>
  </xsl:template>
  <xsl:template match="param">
    <xsl:value-of select="@value"/>
    <xsl:if test="position() != last()">, </xsl:if>
  </xsl:template>
</xsl:stylesheet>

Alternatively you can iterate through the parameters:

<xsl:template match="/parameters">
  <xsl:for-each select="param">
    <xsl:value-of select="@value"/>
    <xsl:if test="position() != last()">, </xsl:if>
  </xsl:for-each>
</xsl:template>

cheers,
b.

| brian martinez                           brian.martinez@xxxxxxxxxxx |
| lead gui programmer                                    303.357.3548 |
| cheap tickets, part of trip network                fax 303.357.3380 |
| 6560 greenwood plaza blvd., suite 400           englewood, co 80111 |
| cendant travel distribution services   http://www.cheaptickets.com/ |

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords