"Jyrki Keisala" <> wrote in message
news:Xns94637E3E127FEjiikoomailsuominet@212.50.131 .130...
> this would get represented with my XSL transformation as
>
> <table>
> <tr>
> <td>elem1</td>
> <td>elem2</td>
> <td>elem3</td>
> <td>elem4</td>
> </tr>
> <tr>
> <td>fii</td>
> <td> </td>
> <td> </td>
> <td>foo</td>
> </tr>
> </table>
>
> It seems a bit tedious to use the structure
>
> <td>
> <xsl:choose>
> <xsl:when test="string-length(elem1) > 0">
> <xsl:value-of select="elem1"/>
> </xsl:when>
> <xsl
therwise>
>
> </xsl
therwise>
> </xsl:choose>
> </td>
>
Hi,
I agree with the other poster : XSL can get tedious. The standard
technique in programming to allow reuse (instead of code duplication) is of
course, abstraction. So you could take the code snippets you wrote and work
them into a template that is invoked as needed. For example : assuming that
<XPathA> is an XPath expression that selects all the nodes that would be
output into your table, you could write :
<xsl:template name="drawTable">
<xsl

aram name="nodes" />
<xsl

aram name="defaultValue" />
<xsl:for-each select="$nodes">
<td>
<xsl:choose>
<xsl:when test="string-length(elem1) > 0">
<xsl:value-of select="elem1"/>
</xsl:when>
<xsl

therwise><xsl:value-of select="$defaultValue"
/></xsl

therwise>
</xsl:choose>
</td>
</xsl:for-each>
</xsl:template>
...and invoke this by saying :
<xsl:call-template name="drawTable">
<xsl:with-param name="nodes" select="<XPathA>" />
<xsl:with-param name="defaultValue" select=" " />
</xsl:call-template>
This abstraction may or may not work for you. The abstraction needs to
be tuned to your application and your programming style.
Regards,
Kenneth