Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: XSL transformation not works for code reuse >Thread Next - Re: XSL transformation not works for code reuse Re: XSL transformation not works for code reuseTo: NULL Date: 12/2/2005 5:10:00 PM "Magnus Henriksson" <magnus.henriksson@N...> wrote in message
news:dmoti0$bqp$1@n......
> "Rushi" <IMS.Rushikesh@g...> wrote in message
> news:1133428891.024801.12260@g......
>> <xsl:template name="format-book">
>> <xsl:param name="Rate" />
>> <xsl:param name="Book" />
>>
>> <xsl:choose>
>> <xsl:when test="$Rate < 4">
>> <tr bgcolor="red">
>> <td><xsl:value-of select="$Book/Name" /></td>
>> <td><xsl:value-of select="$Rate" /></td>
>> </tr>
>> </xsl:when>
>> <xsl:otherwise>
>> <tr bgcolor="lightblue">
>> <td><xsl:value-of select="$Book/Name" /></td>
>> <td><xsl:value-of select="$Rate" /></td>
>> </tr>
>> </xsl:otherwise>
>> </xsl:choose>
>>
>> </xsl:template>
>
>> This sample is working fine, but think if user want change in
>> presentation style then we need to update both code, although they are
>> doing same stuff.....and also think if coder want to change structure
>> of XML file then also we need to change both parts (ie. When tag and
>> Otherwise tag).
>
>> But is there any alternative??????
>
> Divide and conquer! Create a new named template that outputs the <tr>
> element and call that template from <when> and <otherwise>.
>
> // Magnus
>
>
Or just reorder the logic and use a variable:
<xsl:variable name="bgColor">
<xsl:choose>
<xsl:when test="$Rate < 4">red</xsl:when>
<xsl:otherwise>lightblue</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr bgcolor="$bgColor">
<td><xsl:value-of select="$Book/Name" /></td>
<td><xsl:value-of select="$Rate" /></td>
</tr>
--
Joe Fawcett - XML MVP
https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17A5
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
