1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:fox="http://xml.apache.org/fop/extensions">
<xsl:variable name="nb-colonnes">
<xsl:call-template name="profondeur-arbre">
<xsl:with-param name="feuille" select="//node[not(node)][1]"/>
</xsl:call-template>
</xsl:variable>
<xsl:template match="/test">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- defines the layout master -->
<fo:layout-master-set>
<fo:simple-page-master master-name="first" page-height="29.7cm" page-width="21cm" margin-top="1cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
<fo:region-body/>
<fo:region-before extent="3cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- starts actual layout -->
<fo:page-sequence master-reference="first" language="en">
<fo:flow flow-name="xsl-region-body" font-family="Arial, Helvetica, sans-serif">
<fo:block>
<fo:table table-layout="fixed">
<!-- IL MANQUE JUSTE A AUTOMATISER LE NOMBRE DE COLONNES -->
<fo:table-body>
<xsl:for-each select="descendant::node[not(parent::node) or count(.|parent::node/node[1]) = 2]">
<fo:table-row>
<xsl:apply-templates select="."/>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="node">
<fo:table-cell border="1px solid black">
<xsl:variable name="nb-lignes" select="count(descendant::node[not(node)])"/>
<xsl:if test="$nb-lignes > 1">
<xsl:attribute name="number-rows-spanned"><xsl:value-of select="$nb-lignes"/></xsl:attribute>
</xsl:if>
<fo:block>
<xsl:value-of select="@value"/>
</fo:block>
</fo:table-cell>
<xsl:choose>
<xsl:when test="node[1]">
<xsl:apply-templates select="node[1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="cellules-vides">
<xsl:with-param name="nb-cellules" select="$nb-colonnes - count(ancestor::node) - 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="cellules-vides">
<xsl:param name="nb-cellules"/>
<xsl:if test="$nb-cellules > 0">
<fo:table-cell border="1px solid black">
<fo:block/>
</fo:table-cell>
<xsl:call-template name="cellules-vides">
<xsl:with-param name="nb-cellules" select="$nb-cellules - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="profondeur-arbre">
<xsl:param name="profondeur" select="1"/>
<xsl:param name="feuille"/>
<xsl:variable name="profondeur-feuille" select="count($feuille/ancestor::node) + 1"/>
<xsl:choose>
<xsl:when test="$feuille/following::node[not(node)]">
<xsl:call-template name="profondeur-arbre">
<xsl:with-param name="feuille" select="$feuille/following::node[not(node)][1]"/>
<xsl:with-param name="profondeur">
<xsl:choose>
<xsl:when test="$profondeur-feuille > $profondeur">
<xsl:value-of select="$profondeur-feuille"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$profondeur"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$profondeur"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet> |
Partager