Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2007, 11:41 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Pass xsl:param to xsl:if

Hi,
I am building a search engine for my end uses that also would allow them to use XPATH to search the XML files.

I am writing the XSLT and was wondering if I can pass a Parameter to a xsl:if statement?

This returns a TRUE boolean even if its false:
Code:
    <xsl:param name="myxpath">//dispatch</xsl:param>

        <xsl:for-each select="document($xx)">
                                    <xsl:for-each select="/">
                                        <xsl:variable name="content" select="."/>
                                        <xsl:choose>
                                            <xsl:when test="$myxpath">
                                                <a href="{$mychap}">
                                                    <xsl:value-of select="//title"/>
                                                </a>
                                                <br/>
                                            </xsl:when>
                                        </xsl:choose>
                                    </xsl:for-each>
Thanks
 
Old September 6th, 2007, 12:01 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can certainly pass a parameter to xsl:if, but the value must be a boolean, not a string containing an XPath expression that can be evaluated to return a boolean!

The only way to evaluate XPath expressions contained in run-time strings is to use an extension function such as saxon:evaluate().

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 6th, 2007, 12:12 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Michael,

As always. Thanks for the help.

Bones


 
Old September 6th, 2007, 12:22 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Some XSLT processors do actually allow the passing of XPath expressions in as parameters (I'm thinking of AltovaXml specifically).

The following works:

altovaxml /xslt2 test.xsl /in test.xml /param myxpath="//dispatch"

however as Michael says, there is no way to do this from within a stylesheet.

/- Sam Judson : Wrox Technical Editor -/
 
Old September 6th, 2007, 01:12 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Actually, I don't think it passes the expression itself as a parameter - it evaluates the expression and passes its result as the parameter value. But that may be enough for your needs.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 6th, 2007, 04:37 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thanks Michael & Sam

I use XMLspy

As for Saxon:

Currently I use Saxon 8.8 with Kernow interface. My app is .NET. I have no clue on how to add an extension and use it within my XSLT. I Have both your books (XSLT 2.0 & XPATH 2.0) and will research tonight.

Thanks!




Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
Pass link values as xsl:parameter to php5 then xsl pauljr8 XSLT 1 July 2nd, 2007 10:32 PM
xsl:variable holding name of an xsl:param perissos XSLT 0 December 5th, 2006 07:09 AM
The difference between xsl:variable and xsl:param NEO1976 XML 2 July 24th, 2006 06:05 AM
XSL Parameter xsl:param Harinath Chikoti XSLT 1 May 6th, 2005 03:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.