This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: XSL Java Extension problem.


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:

  '4:5:6:7:'
  or
  '2:7:8:'

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" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

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

---
Jeni Tennison
http://www.jenitennison.com/


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]