Sign Up
Search
Options
search
Chat
Help
News
Log in
Not Logged in
Home
»
Boards
»
Stylus Studio Developer Network
»
XSLT Help and Discussion
»
build parameter as string
Topic
Topic Page
1
2
3
4
5
6
7
8
9
Prev Topic
Next Topic
next
Subject:
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.
next
Subject:
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
next
Subject:
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.
next
Subject:
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
top
Subject:
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
Prev Topic
Next Topic
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 to Conference:
Select Conference
Stylus Studio Feature Requests
Stylus Studio Technical Forum
Website Feedback
XSLT Help and Discussion
XQuery Help and Discussion
Stylus Studio FAQs
Stylus Studio Code Samples & Utilities
Stylus Studio Announcements
go
Log In Options
Username:
Password:
Site Map
|
Privacy Policy
|
Terms of Use
|
Trademarks
Stylus Scoop XML Newsletter:
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.