Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 November 1st, 2007, 03:50 AM
Authorized User
 
Join Date: Oct 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default with-param nodeset

Hi again,
I again have a question that i think is quite simple, but i just cant find it on google or this forum, because i don't know what to search for :(

I am trying to make a select box with multiple languages, I have made a template that displays the select box :

Code:
<xsl:template name="select">
    <xsl:param name="name" />
    <xsl:param name="selected" />
    <xsl:param name="options" />
    <select>
        <xsl:attribute name="name">
            <xsl:value-of select="$name" />
        </xsl:attribute>
        <xsl:for-each select="$options/option">
            <option>
                <xsl:attribute name="value">
                    <xsl:value-of select="value" />
                </xsl:attribute>
                <xsl:if test="name = $selected">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="name" />
            </option>
        </xsl:for-each>
    </select>
</xsl:template>
I call this template with this code :

Code:
<xsl:call-template name="select">
    <xsl:with-param name="options">
        <option>
            <name>English</name>
            <value>en</value>
        </option>
        <option>
            <name>Netherlands</name>
            <value>nl</value>
        </option>
    </xsl:with-param>
    <xsl:with-param name="name">languageLanguage</xsl:with-param>
</xsl:call-template>
problem is, it seems that the parameter 'options' is seen as a 'string' and not a 'nodeset', i get the folowwing errors:
- Invalid type
- runtime error
- Failed to evaluate the 'select' expression
The errors apply to the for-each in the 'select' template.

Any ideas how I can send a 'nodeset' with a param? or am I getting my implementation wrong? Any help would be apreciated

 
Old November 1st, 2007, 04:05 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT 1.0 has this crazy restriction that when you create a temporary tree (called a "result tree fragment"), which is what your with-param is doing, then the only two things you can do with the value are (a) copy it using copy-of, or (b) reduce it to a string. Many processors let you get round this with an xx:node-set() extension function - the actual name varies from one processor to another - you can then write <xsl:for-each select="xx:node-set($options)/option">.

Alternatively, use XSLT 2.0 which removes this restriction.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 1st, 2007, 05:29 AM
Authorized User
 
Join Date: Oct 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the information Michael.
I found out that my php5 has exslt support.
Tough i can't seem to figure out how it works.
I have 1 stylesheet ('main') wich includes another stylesheet ('forms').
In both stylesheets i have put this line of code :
Code:
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
inside the xsl:stylesheet element.
My for-each element looks like this now :
Code:
<xsl:for-each select="exsl:node-set($options)/option">
Wich doesn't seem to work, all my errors are gone, tough in my output there are no 'options' in the 'selectbox'. I tried a lot to get this to work, but the best i got was this line:
Code:
<xsl:for-each select="exsl:node-set($options)/*">
wich produces 2 'options' in the 'selectbox', tough there is no 'name' nor a 'value' in the option.

I read the exslt.org website, but i think i did everthing they said.
On php.net manual it states that someone used the prefix exslt instead of exsl, wich did the trick for them, but first of all i dont believe that and second it doesn't work for me.


 
Old November 1st, 2007, 05:37 AM
Authorized User
 
Join Date: Oct 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

offtopic: Michael, on the exslt.org website it says this about supported processors:

SAXON from Michael Kay (version 6.3)

when i click this link i go here :

http://users.iclway.co.uk/mhkay/saxon/index.html

wich is a site that doesn't exist, maybe you should them them your link not working anymore

 
Old November 1st, 2007, 05:53 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The latest versions of SAXON are available here: http://saxon.sourceforge.net/

/- Sam Judson : Wrox Technical Editor -/
 
Old November 1st, 2007, 05:55 AM
Authorized User
 
Join Date: Oct 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i understand sam, i just was telling Michael that the link to his processor on the exslt site doesn't work, thanks anyway.

ontopic: anyone knows what i am doing wrong, 2 posts ago?

 
Old November 1st, 2007, 06:53 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please post a complete stylesheet and show the output you are getting from it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
select nodeset newbies1234 XSLT 4 August 22nd, 2008 10:52 AM
Reversing nodeset sudhish.sikhamani XSLT 3 June 19th, 2008 11:43 AM
comparing nodeset stolte XSLT 7 May 30th, 2007 03:58 PM
Nodeset as Parameter... venutm XSLT 6 February 24th, 2006 03:07 PM
Passing nodeset into position() function EstherMStrom XSLT 1 May 18th, 2005 04:04 PM





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