This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem with conditional parameter in call-template


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]