[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Problem with conditional parameter in call-templat

Subject: Re: Problem with conditional parameter in call-template
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 4 Sep 2001 10:14:11 +0100
xsl conditional parameters
Hi Carlos,

> I'm simplifying my xsl code and I faced a problem. I can't put
> <xsl:choose> either <xsl:if> elements inside a <xsl:call-template>
> so there is a parameter (the one called tipus) that should be
> password when the name of the node is contrasenya and that should be
> text when the node has another name.

You can put any instructions you like in the content of xsl:with-param
to set the value of the parameter. I'd do:

  <xsl:call-template name="entradaTexte">
    <xsl:with-param name="id" select="@id" />
    <xsl:with-param name="valor" select="valor" />
    <xsl:with-param name="tipus">
      <xsl:choose>
        <xsl:when test="name() = 'contrasenya'">password</xsl:when>
        <xsl:otherwise>text</xsl:otherwise>
      </xsl:choose>
    </xsl:with-param>
  </xsl:call-template>

Note that I've used the select attribute to set the other parameters
as it's shorter and passes in the nodes themselves rather than result
tree fragments. If you wanted to save space on setting the $tipus
parameter (and pass in a string rather than a result tree fragment)
then you could use:

  <xsl:with-param name="tipus"
    select="substring('password text',
                      9 * not(name() = 'contrasenya') + 1, 8)" />
  
If the node whose name you're testing is an element (rather than an
attribute), you should probably change the name() = 'contrasenya' to
self::contrasenya as this is a more robust way of testing the type of
the current node.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.