I am creating a table via xsl-fo. So far it worked because the source xml would only contain one document resulting in one tables. I am currently switching to a source xml containing multiple documents. My xsl shall work with both types of sources. This is mostly working; only the table row numbering with xsl:number doesn't.
My XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dxl="http://www.lotus.com/dxl"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:cpfo="http://www.compart.net/xmlns/cpfo">
<xsl:param name="zeilenhoehe">
4.3mm
</xsl:param>
<xsl:output method="xml" />
<xsl:decimal-format decimal-separator="," grouping-separator="." />
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master
master-name="ErsteSeite" page-height="297mm" page-width="210mm"
margin-left="25mm" margin-right="12.5mm" margin-top="10mm"
margin-bottom="12.5mm">
<fo:region-body margin-bottom="54pt" />
<fo:region-after extent="54pt" />
</fo:simple-page-master>
<fo:simple-page-master
master-name="FolgeSeite" page-height="297mm" page-width="210mm"
margin-left="25mm" margin-right="12.5mm" margin-top="10mm"
margin-bottom="12.5mm">
<fo:region-body region-name="FolgeBody" margin-top="35mm" margin-bottom="54pt">
</fo:region-body>
<fo:region-before extent="25mm" region-name="FolgeKopfzeile" />
<fo:region-after extent="12mm" region-name="FolgeFußzeile" />
</fo:simple-page-master>
<fo:page-sequence-master master-name="Seitenfolge">
<fo:single-page-master-reference master-reference="ErsteSeite" />
<fo:repeatable-page-master-reference master-reference="FolgeSeite"/>
</fo:page-sequence-master>
<fo:page-sequence-master master-name="FolgeSeiten">
<fo:repeatable-page-master-reference master-reference="FolgeSeite" />
</fo:page-sequence-master>
</fo:layout-master-set>
<xsl:for-each select="//dxl:document">
<fo:page-sequence master-reference="FolgeSeiten">
<fo:flow flow-name="FolgeBody">
<xsl:if
test="dxl:item[@name='FLT']//dxl:text = 'ja' and dxl:item[@name='Mängeltexte']//dxl:text != ''">
<fo:block font-size="11pt" font-weight="bold" padding-before="5pt" padding-after="10pt">
Feststellungen, Hinweise, Mängel
</fo:block>
<fo:table display-align="center" font-size="8pt" border="0.5pt solid black">
<fo:table-column column-width="9mm" border-right="0.5pt solid black" />
<fo:table-column column-width="13mm" border-right="0.5pt solid black" />
<fo:table-header background-color="#E6E6E6" font-weight="bold">
<fo:table-row>
<fo:table-cell height="6mm" padding-start="1mm" padding-end="1mm">
<fo:block>Pos.</fo:block>
</fo:table-cell>
<fo:table-cell height="6mm" padding-start="1mm" padding-end="1mm">
<fo:block>Kennz.</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body display-align="center">
<xsl:for-each select="dxl:item[starts-with(@name, 'Pos_Leistungsart_')]">
<xsl:param name="lfdnr" select="substring-after( @name , 'Pos_Leistungsart_')" />
<xsl:if test="../dxl:item[@name=concat('Pos_Leistungsart_', $lfdnr)]//dxl:text = 'F'">
<fo:table-row border-top="0.5pt solid black">
<fo:table-cell height="6mm"
padding-start="1mm" padding-end="1mm">
<fo:block>
<xsl:number
count="//dxl:document[current()]/dxl:item[starts-with(@name, 'Pos_Leistungsart_') and dxl:textlist/dxl:text = 'F']" />
</fo:block>
</fo:table-cell>
<fo:table-cell height="6mm"
padding-start="1mm" padding-end="1mm">
<fo:block>
<xsl:value-of
select="../dxl:item[@name=concat('Pos_Kennziffer_', $lfdnr)]//dxl:text" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:if>
</xsl:for-each>
</fo:table-body>
</fo:table>
</xsl:if>
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>
</xsl:stylesheet>
My source, one document, working:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE document SYSTEM 'xmlschemas/domino_9_0_1.dtd'>
<document xmlns='http://www.lotus.com/dxl' version='9.0' maintenanceversion='1.0'
replicaid='C12571F000528D73' form='Prüfung'>
<item name='FLT'><textlist><text>ja</text></textlist></item>
<item name='Mängeltexte'><textlist><text>50$650101$65 Einspeisemessung$01 Allgemein$01 Beschichtung des Behälters beschädigt/ nicht wirksam$B - erheblicher Mangel$<break
/></text></textlist></item>
<item name='Pos_Leistungsart_1'><textlist><text>D</text></textlist></item>
<item name='Pos_Kennziffer_1'><textlist><text>000001</text></textlist></item>
<item name='Pos_Leistungsart_2'><textlist><text>D</text></textlist></item>
<item name='Pos_Kennziffer_2'><textlist><text>000300</text></textlist></item>
<item name='Pos_Leistungsart_3'><textlist><text>D</text></textlist></item>
<item name='Pos_Kennziffer_3'><textlist><text>020407</text></textlist></item>
<item name='Pos_Leistungsart_4'><textlist><text>D</text></textlist></item>
<item name='Pos_Kennziffer_4'><textlist><text>020012</text></textlist></item>
<item name='Pos_Leistungsart_5'><textlist><text>F</text></textlist></item>
<item name='Pos_Kennziffer_5'><textlist><text>650101</text></textlist></item>
<item name='Pos_Leistungsart_6'><textlist><text>F</text></textlist></item>
<item name='Pos_Kennziffer_6'><textlist><text>123456</text></textlist></item>
<item name='Pos_Preis_6'><textlist><text/></textlist></item>
<item name='Pos_Leistungsart_7'><textlist><text/></textlist></item>
<item name='Pos_Kennziffer_7'><textlist><text/></textlist></item>
<item name='Pos_Leistungsart_8'><textlist><text/></textlist></item>
<item name='Pos_Kennziffer_8'><textlist><text/></textlist></item>
<item name='Pos_Leistungsart_9'><textlist><text/></textlist></item>
<item name='Pos_Kennziffer_9'><textlist><text/></textlist></item>
<item name='Pos_Leistungsart_10'><textlist><text/></textlist></item>
<item name='Pos_Kennziffer_10'><textlist><text/></textlist></item>
</document>
My source, multiple documents, numbering not working
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE database SYSTEM 'xmlschemas/domino_9_0_1.dtd'>
<database xmlns='http://www.lotus.com/dxl' version='9.0' maintenanceversion='1.0'
replicaid='C12571F000528D73' path='di\anlsich\di_dg.nsf' title='Druckgeräte'
templatename='DruckgeräteMaster' allowstoredforms='false' maintainunread='false'
optimizetablebitmaps='true' increasemaxfields='true'>
<document form='Prüfung'>
<item name='FLT'><text>ja</text></item>
<item name='Mängeltexte'><text>40$100401$10 SCHUTZ VOR BRANDLASTEN$04 ABSTAND$01 ABSTAND ZU EINER GERINGEN BRANDLAST KLEINER ALS 5 M (AUSNAHME SIEHE UG 06)<break
/>Brandlast: Holzkiste mit Brennholz unmittelbar am FLT$H - geringfügiger Mangel$<break
/>50$010605$01 BEHÄLTERAUSRÜSTUNG - ALLGEMEIN$06 FARBANSTRICH - KORROSIONSSCHUTZ$05 VERSCHMUTZT$H - geringfügiger Mangel$<break
/>60$020207$02 BEHÄLTERAUSRÜSTUNG - SICHERHEITSTECHNISCHE EINRICHTUNGEN$02 MANOMETER$07 ANGEZEIGTER WERT AM BETRIEBSMANOMETER WEICHT ERHEBLICH AB$H - geringfügiger Mangel$<break
/>70$020306$02 BEHÄLTERAUSRÜSTUNG - SICHERHEITSTECHNISCHE EINRICHTUNGEN$03 SICHERHEITSVENTIL$06 ANSPRECHDRUCK UNTERHALB DER ZULÄSSIGEN TOLERANZ$B - erheblicher Mangel$<break
/></text></item>
<item name='Pos_Leistungsart_1'><text>D</text></item>
<item name='Pos_Kennziffer_1'><text>000001</text></item>
<item name='Pos_Leistungsart_2'><text>D</text></item>
<item name='Pos_Kennziffer_2'><text>000001</text></item>
<item name='Pos_Leistungsart_3'><text>D</text></item>
<item name='Pos_Kennziffer_3'><text>000101</text></item>
<item name='Pos_Leistungsart_4'><text>F</text></item>
<item name='Pos_Kennziffer_4'><text>100401</text></item>
<item name='Pos_Leistungsart_5'><text>F</text></item>
<item name='Pos_Kennziffer_5'><text>010605</text></item>
<item name='Pos_Leistungsart_6'><text>F</text></item>
<item name='Pos_Kennziffer_6'><text>020207</text></item>
<item name='Pos_Leistungsart_7'><text>F</text></item>
<item name='Pos_Kennziffer_7'><text>020306</text></item>
<item name='Pos_Leistungsart_8'><text/></item>
<item name='Pos_Kennziffer_8'><text/></item>
<item name='Pos_Leistungsart_9'><text/></item>
<item name='Pos_Kennziffer_9'><text/></item>
<item name='Pos_Leistungsart_10'><text/></item>
<item name='Pos_Kennziffer_10'><text/></item>
</document>
<document form='Prüfung'>
<item name='FLT'><text>ja</text></item>
<item name='Mängeltexte'><text>30$010605$01 BEHÄLTERAUSRÜSTUNG - ALLGEMEIN$06 FARBANSTRICH - KORROSIONSSCHUTZ$05 VERSCHMUTZT<break
/>Verschmutzt, Reinigung erforderlich$H - geringfügiger Mangel$<break/>40$080104$08 ZUGÄNGLICHKEIT$01 AUFSTELLUNG IM FREIEN$04 ABSTAND DER ÖFFNUNGSLOSEN SEITE DES BEHÄLTERS ZU ZAUN - STRAUCH - GEBÄUDEWAND - SCHUTZWAND KLEINER ALS 0.5 M<break
/>Abstand der öffnungslosen Seiten des Behälters zu Zaun, Strauch, Gebäudewand, Schutzwand <0,5m, Sträucher um und unter dem Behälter freischneiden.$H - geringfügiger Mangel$<break
/></text></item>
<item name='Pos_Leistungsart_1'><text>D</text></item>
<item name='Pos_Kennziffer_1'><text>000001</text></item>
<item name='Pos_Leistungsart_2'><text>D</text></item>
<item name='Pos_Kennziffer_2'><text>000005</text></item>
<item name='Pos_Leistungsart_3'><text>F</text></item>
<item name='Pos_Kennziffer_3'><text>010605</text></item>
<item name='Pos_Leistungsart_4'><text>F</text></item>
<item name='Pos_Kennziffer_4'><text>080104</text></item>
<item name='Pos_Leistungsart_5'><text/></item>
<item name='Pos_Kennziffer_5'><text/></item>
<item name='Pos_Leistungsart_6'><text/></item>
<item name='Pos_Kennziffer_6'><text/></item>
<item name='Pos_Leistungsart_7'><text/></item>
<item name='Pos_Kennziffer_7'><text/></item>
<item name='Pos_Leistungsart_8'><text/></item>
<item name='Pos_Kennziffer_8'><text/></item>
<item name='Pos_Leistungsart_9'><text/></item>
<item name='Pos_Kennziffer_9'><text/></item>
<item name='Pos_Leistungsart_10'><text/></item>
<item name='Pos_Kennziffer_10'><text/></item>
</document>
<document form='Prüfung'>
<item name='FLT'><text>ja</text></item>
<item name='Mängeltexte'><text/></item>
<item name='Pos_Leistungsart_1'><text>D</text></item>
<item name='Pos_Kennziffer_1'><text>000001</text></item>
<item name='Pos_Leistungsart_2'><text>D</text></item>
<item name='Pos_Kennziffer_2'><text>000300</text></item>
<item name='Pos_Leistungsart_3'><text/></item>
<item name='Pos_Kennziffer_3'><text/></item>
<item name='Pos_Leistungsart_4'><text/></item>
<item name='Pos_Kennziffer_4'><text/></item>
<item name='Pos_Leistungsart_5'><text/></item>
<item name='Pos_Kennziffer_5'><text/></item>
<item name='Pos_Leistungsart_6'><text/></item>
<item name='Pos_Kennziffer_6'><text/></item>
<item name='Pos_Leistungsart_7'><text/></item>
<item name='Pos_Kennziffer_7'><text/></item>
<item name='Pos_Leistungsart_8'><text/></item>
<item name='Pos_Kennziffer_8'><text/></item>
<item name='Pos_Leistungsart_9'><text/></item>
<item name='Pos_Kennziffer_9'><text/></item>
<item name='Pos_Leistungsart_10'><text/></item>
<item name='Pos_Kennziffer_10'><text/></item>
</document>
</database>
I tried to change the "count" parameter to ../dxl:item[...]
, but that is not allowed with count. I also tried to move the table row generation to a <xsl:template select="//dxl:document>
so that the Pos_Leistungsart_* items would be in the descendant axis, but I think the processor didn't even call the template.
Is there a way to number the table rows?
Your current call on xsl:number appears to be
<xsl:number count="//dxl:document[current()]/dxl:item[
starts-with(@name, 'Pos_Leistungsart_')
and dxl:textlist/dxl:text = 'F']" />
Now, that doesn't actually make much sense. The value of count
is a pattern, and a //
at the start of a pattern makes no difference to the nodes it matches. Further the predicate [current()]
makes no sense - it will be true if there is a context item, which there is. All your dxl:item
elements are children of a dxl:document
, so as far as I can see, you could simply leave out the //dxl:document[current()]/
at the start of the pattern.
The significant difference in your second XML isn't that the document
elements are now children of a database
element; rather, the significant factor seems to be that the text
elements are no longer wrapped in a textlist
element, while the count
pattern explicitly counts only those items where dxl:textlist/dxl:text = 'F'
.