RE: [xsl] about using templates

Subject: RE: [xsl] about using templates
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 12 Jun 2002 10:08:05 +0100
> prehap it is easier to explain this with an example... 
> suppose there are 2 
> xsl stylesheet (XSL1 and XSL2)
> in XSL1 it contain the following: -
> 
> <xsl:template name="key1">fault/unit=key234HrsWft</xsl:template>
> <xsl:template name="key2">data</xsl:template>
> <xsl:template name="key3">some key</xsl:template>
> 
> in XSL2 i will call the following template to retrieve the 
> values store in 
> the three key template: -
> 
> <xsl:template name="query_str">
> 	 <p><xsl:call-template name="key1"/></ip> and
> 	 <p><xsl:call-template name="key2"/></p> and 
> 	 <p><xsl:call-template name="key3"/></p> and 
> 	 </xsl:template>
> so the output result should be: - 
> <p>key234HrsWft</p> and <p>data</p> and <p>soome key</p>

Actually the first result will be <p>fault/unit=key234HrsWft</p> with
this data.
> 
> the problem is, if key2 contain no data (ie <xsl:template 
> name="key2"></xsl:template>) the output will becoming 
> <p>key234HrsWft</p> 
> and <p></p> and <p>soome key</p>
> therefore, i was wondering, how could i selectively add the " 
> and " string 
> into the output file (e.g. only add the " and " string if key2 is not 
> empty). 

It's not clear to me where you want to add the quotation marks.

But more importantly, I don't understand why you are using named
templates to produce these values rather than variables. If you wrote

<xsl:variable name="key2">data</xsl:variable>

then the problem would be much easier.

If you can't rewrite the templates as variables, then you can achieve
the same effect by capturing the result of the template in a variable:

<xsl:variable name="key2">
	<xsl:call-template name="key2"/>
</xsl:variable>

And then you can test $key2=''.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


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


Current Thread