xsl-list
[Top] [All Lists]

RE: with-parameter?

2003-09-04 03:40:08
You are passing your template a set of names:

         <xsl:with-param name="cname"
select="following-sibling::component/name" />

when you should be passing a single name:

         <xsl:with-param name="cname"
select="following-sibling::component[1]/name" />

When you test $cname = "x", it tests if any member of the set is equal
to "x".

Michael Kay

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
kommersz
Sent: 04 September 2003 10:52
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] with-parameter?


Hi all!

I got the following problem. I've tried to make a
translation in an XSLT file, which converts codes into human 
readable format based upon an internal "translation table". I 
produced the following xsl:


<?xml version="1.0" encoding="iso-8859-2"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:template match="/root">
  <html>
   <body>
    <xsl:for-each select="component">
     <xsl:if test="position() mod 2=1">
      <xsl:call-template name="component.name">
       <xsl:with-param name="cname" select="name" />
      </xsl:call-template>
      <xsl:choose>
       <xsl:when test="following-sibling::component">
        <xsl:call-template name="component.name">
         <xsl:with-param name="cname" 
select="following-sibling::component/name" />
        </xsl:call-template>
       </xsl:when>
      </xsl:choose>
      <br />
     </xsl:if>
    </xsl:for-each>
   </body>
  </html>
 </xsl:template>

<!-- 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>

Tried to apply it to the following xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>
 <component>
  <name>0000000001</name>
 </component>
 <component>
  <name>0000000005</name>
 </component>
 <component>
  <name>0000000002</name>
 </component>
 <component>
  <name>0000000006</name>
 </component>
 <component>
  <name>0000000004</name>
 </component>
 <component>
  <name>0000000003</name>
 </component>
 <component>
  <name>0000000007</name>
 </component>
</root>

What I would expect, is that all '000000001' will be 
substituted with 'One', and so on. 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

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

Is this a bug, or normal behaviour?

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

Thanks a lot

   k

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



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



<Prev in Thread] Current Thread [Next in Thread>