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

RE: with-parameter?

Subject: RE: with-parameter?
From: Jarno.Elovirta@xxxxxxxxx
Date: Thu, 4 Sep 2003 13:38:35 +0300
xsl when test parameter
Hi,

> <!-- this template should be the "translation table" -->
>  <xsl:template name="component.name">
>   <xsl:param name="cname" />
>   <xsl:choose>
>    <xsl:when test="$cname='0000000001'">
>     One(
>     <xsl:value-of select="$cname" />
>     )
>    </xsl:when>
>    <xsl:when test="$cname='0000000002'">
>     Two(
>     <xsl:value-of select="$cname" />
>     )
>    </xsl:when>
>    <xsl:when test="$cname='0000000003'">
>     Three(
>     <xsl:value-of select="$cname" />
>     )
>    </xsl:when>
>    <xsl:when test="$cname='0000000004'">
>     Four(
>     <xsl:value-of select="$cname" />
>     )
>    </xsl:when>
>    <xsl:otherwise>
>     <xsl:value-of select="$cname" />
>    </xsl:otherwise>
>   </xsl:choose>
>  </xsl:template>
> </xsl:stylesheet>

[snip]

> What I would expect, is that all '000000001' will be
> substituted with 'One', and so on.

But why do you have the "(
     <xsl:value-of select="$cname" />
     )" in your stylesheet, then? Just use

  <xsl:when test="$cname='0000000001'">One</xsl:when>

if you only want "One"

> But doing all the above
> with Xalan, IE, or Mozilla results in the following:
>
> One(0000000001)Two(0000000005)
> Two(0000000002)Three(0000000006)
> Four(0000000004)Three(0000000003)
> 0000000007

Which is correct. What do you want?

> I don't know how it may happen, that if I pass '0000000005',
> it will print 'Two'?

No, because you don't have a xsl:when that would match "0000000005", so the xsl:otherwise will be used and it will print out the cname parameter value.

> Is this a bug, or normal behaviour?

It's a bug in your stylesheet if the stylesheet doesn't generate what you could want it to generate.

> However, if someone knows a better way to do this
> "translation" of codes to descriptive text, please let me know.

E.g.

  <xsl:template name="component.name">
    <xsl:param name="cname" />
    <xsl:choose>
      <xsl:when test="$lookup[@key = $cname]">
        <xsl:value-of select="$lookup[@key = $cname]/@value"/> ( <xsl:value-of select="$cname"/>)
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$cname"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:variable name="lookup" select="document('')/*/x:lookup/item" xmlns:x="x"/>
  <x:lookup xmlns:x="x">
    <item key="0000000001" value="One" />
    <item key="0000000002" value="Two" />
    <item key="0000000003" value="Three" />
    <item key="0000000004" value="Four" />
  </x:lookup>

Cheers,

Jarno - Feindflug: Lagerhaft

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


Current Thread
  • with-parameter?
    • kommersz - Thu, 4 Sep 2003 05:59:07 -0400 (EDT)
      • <Possible follow-ups>
      • Jarno . Elovirta - Thu, 4 Sep 2003 06:38:49 -0400 (EDT) <=

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.