Re: [xsl] XSL Java Extension problem.

Subject: Re: [xsl] XSL Java Extension problem.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 1 Nov 2001 16:38:11 +0000
Hi Sudhir,

> I found that all my stylesheets were same but differed in the
> columns (in the XML) I was processing, for example I was doing
> <xsl:apply-templates select="td[4] | td[5] | td[6] | td[7]"/>
> in one stylesheet vs
> <xsl:apply-templates select="td[2] | td[7] | td[8]"/>
> in the other.
> Is there any other way to have a generic stylesheet which will
> accept the column values as parameters?

Yes. You could pass them in as a string value:


Assuming this was the value of the $columns parameter for the
stylesheet, you could then count how many columns your table needed by
counting how many ':'s the string contained with:

  string-length(translate($columns, '0123456789', ''))

And you could work through the numbers in the list using recursion,
with something like:

<xsl:template name="processColumns">
  <xsl:param name="columns" select="$columns" />
  <xsl:variable name="columnIndex"
                select="substring-before($columns, ':')" />
  <xsl:variable name="remainingColumns"
                select="substring-after($columns, ':')" />

  <xsl:apply-templates select="td[number($columnIndex)]" />

  <xsl:if test="$remainingColumns">
    <xsl:call-template name="processColumns">
      <xsl:with-param name="columns" select="$remainingColumns" />

Alternatively, you could have one stylesheet that held all the common
code, and import that into individual stylesheets that focus on
different columns.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread