xsl-list
[Top] [All Lists]

RE: how to capture a value returned by a template call into a variable

2003-01-09 02:53:16
I suspect there is no @jdbc-type in the context where you are trying to create 
the variable.  Check whether @jdbc-type exists by placing <xsl:value-of 
select="@jdbc-type"/> before you try to create the variable.

The following example uses a subset of your examples, and it works fine.

the xslt file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
        <xsl:template name="translate_type">
                <xsl:param name="db_type"/>
                <xsl:choose>
                        <xsl:when test="$db_type='CHAR'">String</xsl:when>
                        <xsl:when test="$db_type='VARCHAR'">String</xsl:when>
                        <xsl:when 
test="$db_type='LONGVARCHAR'">String</xsl:when>
                </xsl:choose>
        </xsl:template>
        <xsl:template match="testnode">
                <xsl:variable name="java_type">
                        <xsl:call-template name="translate_type">
                                <xsl:with-param name="db_type" 
select="@jdbc-type"/>
                        </xsl:call-template>
                </xsl:variable>
                <xsl:value-of select="$java_type"/>
        </xsl:template>
</xsl:stylesheet>

the example test file.
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="2003-1-9.xslt"?>
<testnode jdbc-type="CHAR"></testnode> 

Edward Middleton

-----Original Message-----
From: Anthony Kong [mailto:anthony(_dot_)kong(_at_)ufjia(_dot_)com]
Sent: Thursday, January 09, 2003 6:14 PM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: RE: [xsl] how to capture a value returned by a template call into a 
variable


Hi, Ed,

The template is as such:

 <xsl:template name="translate_type" >
     <xsl:param name="db_type" />
     <xsl:choose >
         <xsl:when test="$db_type='CHAR'">String</xsl:when>
         <xsl:when test="$db_type='VARCHAR'">String</xsl:when>
         <xsl:when test="$db_type='LONGVARCHAR'">String</xsl:when>
         <xsl:when test="$db_type='NUMERIC'">java.math.BigDecimal</xsl:when>
         <xsl:when test="$db_type='DECIMAL'">java.math.BigDecimal</xsl:when>
         <xsl:when test="$db_type='BIT'">boolean</xsl:when>
         <xsl:when test="$db_type='TINYINT'">byte</xsl:when>
         <xsl:when test="$db_type='SMALLINT'">short</xsl:when>
         <xsl:when test="$db_type='INTEGER'">  int </xsl:when>
         <xsl:when test="$db_type='BIGINT'">  long    </xsl:when>
         <xsl:when test="$db_type='REAL'">  float   </xsl:when>
         <xsl:when test="$db_type='FLOAT'">  double  </xsl:when>
         <xsl:when test="$db_type='DOUBLE'">  double  </xsl:when>
         <xsl:when test="$db_type='BINARY'">  byte[]  </xsl:when>
         <xsl:when test="$db_type='VARBINARY'">  byte[]  </xsl:when>
         <xsl:when test="$db_type='LONGVARBINARY'">  byte[]  </xsl:when>
         <xsl:when test="$db_type='DATE'">  java.sql.Date   </xsl:when>
         <xsl:when test="$db_type='TIME'">  java.sql.Time   </xsl:when>
         <xsl:when test="$db_type='TIMESTAMP'">  java.sql.Timestamp
</xsl:when>
         <xsl:when test="$db_type='CLOB'">  Clob    </xsl:when>
         <xsl:when test="$db_type='BLOB'">  Blob    </xsl:when>
         <xsl:when test="$db_type='ARRAY'">  Array   </xsl:when>
         <xsl:when test="$db_type='DISTINCT'">  mapping of underlying type
</xsl:when>
         <xsl:when test="$db_type='STRUCT'">  Struct  </xsl:when>
         <xsl:when test="$db_type='REF'">  Ref </xsl:when>
         <xsl:when test="$db_type='JAVA_OBJECT'">  underlying Java class
</xsl:when>
    </xsl:choose>
 </xsl:template>


Regards,

Anthony



-----Original Message-----
From: Edward(_dot_)Middleton(_at_)nikonoa(_dot_)net 
[mailto:Edward(_dot_)Middleton(_at_)nikonoa(_dot_)net]
Sent: Thursday, January 09, 2003 3:24 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] how to capture a value returned by a template call
into a variable


You need to post your translate_type template.  What you have posted looks
fine.

Edward Middleton

-----Original Message-----
From: Anthony Kong [mailto:anthony(_dot_)kong(_at_)ufjia(_dot_)com]
Sent: Thursday, January 09, 2003 3:04 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] how to capture a value returned by a template call into a
variable


Hi, all,

I have tried to search by keyword "function" or "template" into the mailing
list but there are no many enties returned in the results. So i have to
venture to ask this question in this list. If the question has appeared
before, please kindly bear with me.

I would like to modularise some common code as a function. But in XSLT 1.0
there is no function facility. My common code involved is to tranlate a DB
type into a java type. That is what i have done:

 <xsl:variable name="java_type">
        <xsl:call-template name="translate_type">
            <xsl:with-param name="db_type" select="@jdbc-type"/>
        </xsl:call-template>
    </xsl:variable>

I intended (wish, actually :-) to capture the result into variable
"java_type". However it failed.

What is a better way to achieve this?


Regards,

Anthony

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


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

 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>