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 December 13th, 2007, 08:08 AM
Registered User
 
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with passing parameters and Xalan

Hi guys,

I'm having trouble passing parameters to xalan. When I do the following:
Code:
<xsl:param name="language" select="otherwise" />


<xsl:template match="if">
    <xsl:choose>
        <xsl:when test="$language">                
            <xsl:value-of select="$language" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="otherwise" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
It actually outputs my param value instead of the node value. I have to following source XML:
Code:
<if>
    <cpp>int</cpp>
    <java>Int</java>
    <otherwise>int</otherwise>
</if>
I pass my parameter to xalan as:
Code:
-param language cpp
Any help much appreciated.

Thanks!


 
Old December 13th, 2007, 08:27 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The parameter you are passing in is just a string, so test="'cpp'" evalutates to true, and <xsl:value-of select="'cpp'"> outputs the string you input.

<xsl:template match="if">
  <xsl:variable name="node" select="*[name()=$language]"/>
<xsl:choose>
        <xsl:when test="$node">
            <xsl:value-of select="$node" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="otherwise" />
        </xsl:otherwise>
    </xsl:choose>


in XSLT 2.0 this could be abbreviated to something like:

<xsl:value-of select="(*[name()=$language] , otherwise)[1]" />

/- Sam Judson : Wrox Technical Editor -/
 
Old December 13th, 2007, 01:36 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You've passed it a string so it has output that string. If you want it to output the value of the node whose name is equal to that string, you have to say so:

<xsl:value-of select="*[name()=$language]"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 13th, 2007, 06:06 PM
Registered User
 
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fantastic. Thanks a lot guys!







Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript in Xsl using-Xalan-Problem angeshwar XSLT 1 May 7th, 2008 12:36 AM
passing parameters fizzerchris Access VBA 5 August 31st, 2007 12:16 PM
Passing parameters tal Ajax 5 May 26th, 2007 08:07 AM
Passing parameters ceema Crystal Reports 0 February 15th, 2006 04:03 AM
Problem passing parameters in Crystal Report. joydip_kanjilal Crystal Reports 0 October 8th, 2004 01:47 AM





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