You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Marc Salvetti <ma...@notremanou.net> on 2005/01/17 13:37:06 UTC
cannot convert a tree fragment in noodelist function
hello,
i'm trying to write a template to convert a html table to pdf
the problem is that the table-fo structure need the table columns to be
declared beforehand.
so i want to find the line of the table with the maximum number of cells
(because of eventual colspan columns) and transform it in columns
declaration.
my template look like this :
<xsl:template match="table">
<fo:table>
<xsl:if test="@cellspacing!=''">
<xsl:attribute name="border-spacing"><xsl:value-of
select="@cellspacing"/></xsl:attribute>
</xsl:if>
<xsl:if test="@cellpadding!=''">
<xsl:attribute name="padding"><xsl:value-of
select="@cellpadding"/></xsl:attribute>
</xsl:if>
<xsl:if test="@width!=''">
<xsl:attribute
name="inline-progression-dimension"><xsl:value-of
select="@width"/></xsl:attribute>
<xsl:attribute name="table-layout">fixed</xsl:attribute>
</xsl:if>
<xsl:variable name="nbCols">
<xsl:for-each select="tr">
<nbCol><xsl:value-of select="count(td)"/></nbCol>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxCol">
<xsl:call-template name="math:max">
<xsl:with-param name="nodes" select="$nbCols" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="positions">
<xsl:for-each select="tr[count(td)=$maxCol]">
<posTd value="{position()}"/>
</xsl:for-each>
</xsl:variable>
<xsl:apply-templates
select="tr[position()=$positions/posTd[position()=1]]/@value"
mode="table-columns"/-->
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="tr" mode="table-columns">
<xsl:for-each select="td">
<fo:table-column column-number="{position()}">
<xsl:if test="@width!=''">
<xsl:attribute name="column-width"><xsl:value-of
select="@width"/></xsl:attribute>
</xsl:if>
</fo:table-column>
</xsl:for-each>
</xsl:template>
<!--template from exslt.org-->
<xsl:template name="math:max">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)">NaN</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$nodes">
<xsl:sort data-type="number" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="number(.)" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The issue is that apparently the max template can't be applied to a tree
fragment. Does anyone have an idea of a workaround ?
thanks for any help
Marc
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: cannot convert a tree fragment in noodelist function
Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Jan 17, 2005, at 11:19 PM, Marc Salvetti wrote:
> Cheers Mark, it's working now
>
ah, great :-)
> my problem is still unsolved through, as i don't see the way to match
> "the first table row that got the max number of cells", but as you
> said, it's more of a xsl mailing list question...
>
> btw, when i look at the doc on exslt.org, the namespace is
>
> xmlns:exsl="http://exslt.org/common"
>
> Do you know the difference with the namespace you gave
> (xmlns:exslt="http://exslt.org/common") ?
You mean "exsl" vs. "exlst"? Only the URI matters. Whatever you call
a namespace locally in an XML document, that doesn't matter... think of
it like an alias.
best,
-ml-
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: cannot convert a tree fragment in noodelist function
Posted by Marc Salvetti <ma...@notremanou.net>.
Cheers Mark, it's working now
my problem is still unsolved through, as i don't see the way to match
"the first table row that got the max number of cells", but as you said,
it's more of a xsl mailing list question...
btw, when i look at the doc on exslt.org, the namespace is
xmlns:exsl="http://exslt.org/common"
Do you know the difference with the namespace you gave (xmlns:exslt="http://exslt.org/common") ?
regards,
Marc
Mark Lundquist a écrit :
>
> On Jan 17, 2005, at 4:37 AM, Marc Salvetti wrote:
>
>> hello,
>>
>> i'm trying to write a template to convert a html table to pdf
>> the problem is that the table-fo structure need the table columns to
>> be declared beforehand.
>> so i want to find the line of the table with the maximum number of
>> cells (because of eventual colspan columns) and transform it in
>> columns declaration.
>>
>> [...snip]
>>
>> The issue is that apparently the max template can't be applied to a
>> tree fragment.
>
>
> Right, not in XSLT 1.0.
>
>> Does anyone have an idea of a workaround ?
>
>
> 1) Use XSLT 2.0 (Saxon); or,
>
> 2) Call the template like this
>
> <xsl:with-param name="nodes" select="exslt:node-set($nbCols)" />
>
> where
>
> xmlns:exslt="http://exslt.org/common"
>
> BTW, there is a mailing list for XSLT questions:
> http://www.mulberrytech.com/xsl/xsl-list/
>
> HTH,
> -ml-
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: cannot convert a tree fragment in noodelist function
Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Jan 17, 2005, at 4:37 AM, Marc Salvetti wrote:
> hello,
>
> i'm trying to write a template to convert a html table to pdf
> the problem is that the table-fo structure need the table columns to
> be declared beforehand.
> so i want to find the line of the table with the maximum number of
> cells (because of eventual colspan columns) and transform it in
> columns declaration.
>
> [...snip]
>
> The issue is that apparently the max template can't be applied to a
> tree fragment.
Right, not in XSLT 1.0.
> Does anyone have an idea of a workaround ?
1) Use XSLT 2.0 (Saxon); or,
2) Call the template like this
<xsl:with-param name="nodes" select="exslt:node-set($nbCols)" />
where
xmlns:exslt="http://exslt.org/common"
BTW, there is a mailing list for XSLT questions:
http://www.mulberrytech.com/xsl/xsl-list/
HTH,
-ml-
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org