XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
giancarlo rossiSubject: build parameter as string
Author: giancarlo rossi
Date: 23 Oct 2006 05:24 AM
Originally Posted: 22 Oct 2006 05:56 PM
I need to build a parameter depending on a xsl:param

<xsl:param name="supplier_param" />

<xsl:variable name="test">
<xsl:choose>
<xsl:when test="$supplier_param">
Complete='true' and Supplier='<xsl:value-of select="$supplier_param" />'
</xsl:when>
<xsl:otherwise>
Complete='true'
</xsl:otherwise>
</xsl:choose>
</xsl:variable>


<--then i pass the string as a parameter -->


<xsl:for-each select="/root[$test]/mynode">
'mycode
</xsl:for each>

but the for-each filter is not applyed.

I tryed also with:

<xsl:for-each select="/root[string($test)]/mynode">
'mycode
</xsl:for each>

with the same results.

Postnext
Ivan PedruzziSubject: build parameter as string
Author: Ivan Pedruzzi
Date: 23 Oct 2006 10:13 AM

XSLT does not allow to create XPath expressions dynamically.

Use the following instead

<xsl:for-each select="/root[Complete='true' and (Supplier = $supplier_param or not($supplier_param))]/mynode">

If "Complete" and "Supplier" are attributes use the prefix @
@Complete='true'


Ivan Pedruzzi
Stylus Studio Team

Postnext
Tony LavinioSubject: build parameter as string
Author: Tony Lavinio
Date: 23 Oct 2006 10:14 AM
You can't do that.
XPaths are resolved at compile time, not run-time.
Variables are not substitution macros.

Instead of <xsl:for-each...> you might want to do pass the
kind of condition in a parameter, and then have something
like this:

<xsl:choose>
<xsl:when test="$supplier_param = ''">
<xsl:apply-templates select="/root[Complete='true']/mynode"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="/root[Complete='true' and and Supplier=$supplier_param]/mynode"/>
</xsl:otherwise>
</xsl:choose>

and then have a template

<xsl:template match="mynode">
'mycode
</xsl:template>

Generally, when you use a for-each, you are not thinking
in the 'XSLT way'. Examine carefully how templates are
used, and you will probably find your code shrinking.

Postnext
giancarlo rossiSubject: build parameter as string
Author: giancarlo rossi
Date: 25 Oct 2006 09:21 AM
Originally Posted: 25 Oct 2006 09:20 AM
Thanks guy,
it works and I understand better the template logic.

Bu I need to try to implement your code:

right now I Have this:

<xsl:for-each select="msxsl:node-set($base)/item[(supplier = $supplier_param or not($supplier_param))]">


<xsl:for-each>

this case filter just one parameter but if I have an array for example:

<xsl:param name="supplier_param" select="Alitalia,easyjet" />

this xpath expression
(msxsl:node-set($base)/item[(supplier = $supplier_param or not($supplier_param))] )

obviulsy not found results.

So the questions is:
Is possible in xsl filter by an array param ?
Thanks in advance

Posttop
Tony LavinioSubject: build parameter as string
Author: Tony Lavinio
Date: 25 Oct 2006 02:39 PM
This is probably not the best way to do this, but not seeing
the rest of your code we can only guess.

... base)/item[contains($supplier_param, supplier)] ...

http://www.w3.org/TR/xpath#function-contains

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.