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

Using XSL parameters to construct variables to constru

Subject: Using XSL parameters to construct variables to construct expressions
From: "Doug Howell (IT)" <DHOWELL@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Mar 2003 16:50:48 -0500
construct variable
(Please forgive me, as I've been away from XSL for a while, and am struggling with a new project.) I'm transforming an XML file via JavaScript, based on user input. 

Approach 1: I'm currently creating a processor via JavaScript, then sending different parameters/modes to it to get search results. If the user chooses to narrow the search, he/she selects an option and I send a parameter to the stylesheet (processor). What I'd like to do inside the stylesheet is to construct a variable on the fly, based on the parameter values, then use that variable as the expression in the apply-templates select attribute value. Something like this:

XML snippet: 
<process>
     <number>1</number>
     <name>evaluate</name>
     <descrip>[Description.]</descrip>
</process>

XSL snippet:
<!-- default value of params is empty string; if user chooses a processArea option, I'll send the parameter to the stylesheet and set this value -->
<xsl:param name="processArea" /><!-- if sent, value will be 1, 2, 3 or 4 -->
. . . 
. . .
<xsl:variable name="selectStatement">/process-report/process
     <xsl:if test="$processArea != ''">[starts-with(number,<xsl:value-of select="$processArea"/>)]</xsl:if>
</xsl:variable>
. . . 
. . . 
<xsl:apply-templates select="$selectStatement"/>
. . . 
. . .

If a parameter is passed in, the parameter would not equal an empty string, so the corresponding predicate expression would become part of the variable. So I could add more predicates depending on the values of other parameters, then use the complete variable in the following apply-templates select statement.

This doesn't seem to work, because the variable will evaluate as a string instead of an expression, right? Is there a way around this?

Approach 2: I could also change the select attribute via script in the Web page, then select the node (using selectSingleNode) and change its value. Just wondering what the trade-offs would be between these two approaches (if the first approach is even possible, that is). Would it work faster, more efficiently?

Thanks,
Doug Howell

 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.