xsl-list
[Top] [All Lists]

solved: Generating <col> or <fo:table-column> tags with widths look ed up from a comma separated string - recursive

2003-10-23 09:38:07

I was able to solve the issues and problems that I described in the
following thread topics, with a different approach: 
(adding them so that keyword searches made on google will help others
with this issue).

- whats the best way to create and use values for  lookup (key-value)
such that you can loop through it with limits
- to convert XSLs from HTML to FO: approach, ideas, thoughts ?
- Converting nested XSL-HTMLs made for complex technical spec documents
into FO, design approach, current layouts, other thoughts - advise
- TOUGH ONE: All Grandmasters - how- iteratable key-value
pair/array/lookup table that has only local scope with the xsl template
- Implementing an Array or Lookup List type of structure in XSL

It uses a comma (or any other char) separated string) to separate the
elements of the so called array or list structure. Of course it
currently does not feature all the possible operations traditionally
available with arrays. But, it's a start in being able to retrieve
values.

It uses a recursive call.

It is particularly good for generating <fo:table-column> for FO using
WIDTHS defined in the XSL and not from XML Data (where it would be
easier to model).

Solution XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template name ="MatrixColumns" >
<xsl:param name ="MatrixColumnWidths"></xsl:param> 

<xsl:choose>

<xsl:when test ="contains($MatrixColumnWidths,',')" >

                
<fo:table-column>
<xsl:attribute name="column-width"><xsl:value-of
select="substring-before($MatrixColumnWidths,',')"></xsl:value-of></xsl:
attribute>
</fo:table-column>
<!--                    
<col>
<xsl:attribute name="width"><xsl:value-of
select="substring-before($MatrixColumnWidths,',')"></xsl:value-of></xsl:
attribute>
</col>
-->
<xsl:call-template name ="MatrixColumns" >
<xsl:with-param name ="MatrixColumnWidths" >
        <xsl:value-of select ="substring-after($MatrixColumnWidths,',')"
/>
</xsl:with-param>
</xsl:call-template>

</xsl:when>

<xsl:otherwise>

<!--
<fo:table-column>
<xsl:attribute name="column-width"><xsl:value-of
select="$MatrixColumnWidths"></xsl:value-of></xsl:attribute>
</fo:table-column>
-->             
<col>
<xsl:attribute name="width"><xsl:value-of
select="substring-before($MatrixColumnWidths,',')"></xsl:value-of></xsl:
attribute>
</col>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

<xsl:template match="/">
<xsl:variable name="WidthsString" select="'10,20,30,40,50'"/>
<xsl:call-template name="MatrixColumns">
<xsl:with-param name="MatrixColumnWidths" select="$WidthsString"/>
</xsl:call-template>
</xsl:template>

</xsl:stylesheet>

XML:

<root>
</root>

Abhishek Sanwal
HP - Houston Campus
abhishek(_dot_)sanwal(_at_)hp(_dot_)com

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



<Prev in Thread] Current Thread [Next in Thread>
  • solved: Generating <col> or <fo:table-column> tags with widths look ed up from a comma separated string - recursive, SANWAL, ABHISHEK (HP-Houston) <=