Re: [xsl] Return value from a template 2...

Subject: Re: [xsl] Return value from a template 2...
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 23 Jan 2008 09:21:14 GMT
> I want to return a value from a template(getIdList)

templates never return values (in the sense of a function
return). Anything they generate is always added to the current output
(whetehr that is the stylesheet result, or a variable).

You haven't said what ypur input looks like, or what output ypiu want or
what transform you are trying to do, so I can make some comments on the
code you posted but can't really suggest any code that you need,
although I make a blind guess at the end.

       <xsl:template match="/root">
               <xsl:variable name="idList">
                       <xsl:call-template select="/root/vid" name="getIdList" />
               <xsl:value-of select="$idList"/>

This is a syntax error you can not have a select attribute on
call-template so you should get no output. If you delete that then
it generates a variable  idList with a document node with child nodes
anything generated by getIdList, it then discards any nodes in that
variable and outputs the string value of $idList.

               <xsl:for-each select=".">

doing a for-each over a single node is a no-op, so it is like not having
the for-each except that variable definitions have skope the current
element so it restricts the scope of $idList"


there is no variable $var in scope at this point (you haven't defined
var yet) What processor are you using, again this should have given you
a syntax error and no output.

if the definition of $var had been syntactivcally correct, it would have
gone out of scope at this point.

               <xsl:value-of select="$var"/>
so this is a reference to an undefined variable.

I suspect that what you want is
<xsl:template match="/root">
 <xsl:for-each select="vid">
 <xsl:value-of select="."/>
 <xsl:if test="position()!=last()">,</xsl:if>

or, in xslt2

<xsl:template match="/root">
<xsl:value-of select="vid" separator=","/>

With no variables at all


The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 

Current Thread