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

RE: Variable - Results Tree Fragment Problem

Subject: RE: Variable - Results Tree Fragment Problem
From: "Martinez, Brian" <brian.martinez@xxxxxxxxxxx>
Date: Wed, 27 Aug 2003 15:45:16 -0600
xsl for each tree
> From: Pappa [mailto:anarkin@xxxxxxxxxxxx]
> Sent: Wednesday, August 27, 2003 2:59 PM
> Subject:  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

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.