fo:Table to html table - xslt -
i'm trying write xslt generate xslt purpose replacing xsl:fo html tags..xslt 1
i use cdata around "xsl" namespace avoid processing kind of tag xslt. scope processing xsl:fo directive , replace example :
<fo:table table-layout="fixed" width="100%" font-size="10pt"> <fo:table-column column-width="proportional-column-width(0.65)"/> <fo:table-column column-width="proportional-column-width(0.35)"/> <fo:table-body> <fo:table-row> <fo:table-cell padding-before="0.5cm"></fo:table-cell> <fo:table-cell padding-before="0.5cm"> <fo:block> y <![cdata[ --> treated text can copy <xsl-valueof select="."/>?? <xsl:choose> <xsl:when test="...xpath'"> <xsl:value-of select="..." />, </xsl:when> <xsl:otherwise> @ <xsl:value-of select=..." />, </xsl:otherwise> </xsl:choose>]]> </fo:block> <fo:block space-before="0.5cm" text-align="center"> x </fo:block> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table>
i want traslate fo:table+fo:table-body table tag, , fo:table-column td width="..%", fo:table-row tr.. td width not easy retrieve because width property belong fo:table-column , fo:table-cell handling tag.
i try loop fo:table-column when read table-cell i'm writing td , calculate width using property column-width obtained precedent tag fo:table-column: use position() of tag table-column (first loop) in fo:table-cell selection
for example here xslt tralslator xsl:fo (above-mentioned):
<xsl:template name="fo-table"> <xsl:param name="font-size" /> <xsl:param name="width" /> <xsl:variable name="cols" select="count(fo:table-column)"/> <xsl:if test="fo:table-column"> <xsl:variable name="effective-cols" select="count(fo:table-body/fo:table-row/fo:table-cell)"/> <xsl:if test="$cols = $effective-cols"> <table> <xsl:for-each select="fo:table-body/fo:table-row"> <tr> <xsl:for-each select="parent::*/parent::*/fo:table-column"> <xsl:variable name="width-proportional"> <xsl:value-of select="@column-width"/> </xsl:variable> <td> <xsl:attribute name="width"> <xsl:call-template name="getpercentwidth"> <xsl:with-param name="proportional-value-width"><xsl:value-of select="$width-proportional"/></xsl:with-param> </xsl:call-template> </xsl:attribute> abc <xsl:variable name="vposition"><xsl:value-of select="position()"/></xsl:variable> <xsl:for-each select="parent::*/fo:table-body/fo:table-row/*[$vposition]"> <xsl:value-of select="local-name()"/><xsl:text> #10;</xsl:text> <!-- debug--> <xsl:choose> <xsl:when test="fo:block"> <xsl:for-each select="fo:block"> <xsl:call-template name="fo-block-table"> <xsl:with-param name="text-align"><xsl:value-of select="@text-align"/></xsl:with-param> <xsl:with-param name="space-before"><xsl:value-of select="@space-before"/></xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:when> <xsl:otherwise> empty cell </xsl:otherwise> </xsl:choose> </xsl:for-each> </td> </xsl:for-each> </tr> </xsl:for-each> </table> </xsl:if> </xsl:if> </xsl:template> <xsl:template name="fo-block-table"> <xsl:param name="text-align" /> <xsl:param name="space-before" /> <xsl:choose> <xsl:when test="$text-align"> <div> <xsl:attribute name="text-align"> <xsl:value-of select="normalize-space($text-align)"/> </xsl:attribute> <xsl:apply-templates select="."/> </div> </xsl:when> <xsl:otherwise> <div> <xsl:apply-templates select="."/> </div> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="getpercentwidth"> <xsl:param name="proportional-value-width"/> <xsl:variable name="width" select="normalize-space($proportional-value-width)"/> <xsl:variable name="begin"> <xsl:value-of select="string-length(substring-before($width, '('))" /></xsl:variable> <xsl:variable name="last"> <xsl:value-of select="string-length(substring-before($width,')'))" /></xsl:variable> <xsl:variable name="val" select="fn:substring($width, $begin, $last)" /> <xsl:variable name="val1" select="substring-after($val,'(')"/> <xsl:variable name="cent" select="100"/> <xsl:value-of select="concat(($val1 * $cent),'%')"/> </xsl:template>
but cant realize why td's contains 'y',x , empty when belong empty table-cell, seems reads fo:block..
<table> <tr> <td width="65%"> abc table-cell #10; empty cell table-cell #10;<div> y </div> <div text-align="center"> x </div> </td> <td width="35%"> abc table-cell #10; empty cell table-cell #10;<div> y </div> <div text-align="center"> x </div> </td> </tr> </table>
i need obtain:
<table> <tr> <td width="65%"> abc table-cell #10; empty cell </td> <td width="35%"> abc table-cell #10; <div> y </div> <div text-align="center"> x </div> </td> </tr> </table>
if replace second loop xsl : for-each with
xsl : template
don't match anything! maybe *[$vposition] doesn't work works if replace number 1 or 2..
what's wrong?
thanks in advice!
roby
the problem line...
<xsl:for-each select="parent::*/fo:table-body/fo:table-row/*[$vposition]">
or rather, due how vposition
variable defined:
<xsl:variable name="vposition"><xsl:value-of select="position()"/></xsl:variable>
by using xsl:value-of
causing vposition
set string value, not numeric value. when use string value in condition, [*$vposition]
return true if string not empty.
try changing variable declaration this, set vposition
number
<xsl:variable name="vposition" select="position()" />
Comments
Post a Comment