I am using below XSLT to generate report with running footer, but the first page of ther report doesn't have the running footer, please advice what needs to be changed
<?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:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts">
<xsl:template match="/" >
<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="290mm" page-width="210mm" margin-top="0mm" margin-bottom="10mm" margin-left="20mm" margin-right="0mm">
<fo:region-body margin-top="15mm" margin-bottom="15mm"/>
<fo:region-after extent="10mm" region-name="footer-normal"></fo:region-after>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="first">
<fo:static-content flow-name="footer-normal">
<fo:block text-align="center" font-size="7pt" font-style="italic" font-family="sans-serif">
<fo:retrieve-marker retrieve-class-name="chapter"/>
PAGE <fo:page-number/> of
<fo:page-number-citation ref-id="last-page"/>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<xsl:for-each select="ArrayOfRoomReportBE/RoomReportBE" >
<xsl:variable name="RoomNo_node" select=".//RoomNumber"/>
<fo:marker marker-class-name="chapter" font-size="7pt" font-style="italic"
font-family="sans-serif">
<xsl:value-of select="$RoomNo_node"/>
</fo:marker>
<!-- Dispaly datat -->
</xsl:for-each>
<fo:block id="last-page"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
Input document used is as follows
<ArrayOfRoomReportBE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RoomReportBE>
<Id>0</Id>
<RoomNumber>TestCap1</RoomNumber>
<RoomName>TestCap1</RoomName>
<Comment>Testing a bit</Comment>
<GeneralAspect>
<GeneralAttributeTitle>
<ReferenceLink>Reference Link</ReferenceLink>
<Notes>General Notes</Notes>
<GeneralHeader>General</GeneralHeader>
<MaxCO2>Max CO2</MaxCO2>
<DimensionHeader>Dimension</DimensionHeader>
<NetAreaTitle>Net area</NetAreaTitle>
<ClimateHeader>Climate</ClimateHeader>
<MinTempTitle>Min Temperature</MinTempTitle>
<MaxTempTitle>Max Temperature </MaxTempTitle>
<OpenHoursTitle>Open hours</OpenHoursTitle>
<NonOpenHoursTitle>Non open hours</NonOpenHoursTitle>
<AcousticsHeader>Acoustics</AcousticsHeader>
<MaxInstallationNoiseTitle>Max installation noise</MaxInstallationNoiseTitle>
<SoundInsulationTitle>Sound insulation</SoundInsulationTitle>
<WorkplacesOccupancyHeader>Occupancy/Workplaces</WorkplacesOccupancyHeader>
<OccupancyTitle>Occupancy</OccupancyTitle>
<NoOfWorkspaceTitle>Number of workplaces</NoOfWorkspaceTitle>
<TypeOfWorkspaceTitle>Type of workplaces</TypeOfWorkspaceTitle>
</GeneralAttributeTitle>
<AspectAttributeItems>
<GeneralAttributeItemBE>
<GeneralNoOfWorkplaces />
<GeneralDimensionNetArea>12</GeneralDimensionNetArea>
<GeneralClimateMinTempOpen>-19°C</GeneralClimateMinTempOpen>
<GeneralClimateMinTempNonOpen>-15°C</GeneralClimateMinTempNonOpen>
<GeneralClimateMaxTempOpen>-6°C</GeneralClimateMaxTempOpen>
<GeneralClimateMaxTempNonOpen>-11°C</GeneralClimateMaxTempNonOpen>
<Notes />
<ReferenceLink />
</GeneralAttributeItemBE>
</AspectAttributeItems>
</GeneralAspect>
<FloorAspect>
<FloorAttributeTitle>
<Description>Description</Description>
<ReferenceLink>Reference Link</ReferenceLink>
<Notes>General Notes</Notes>
<FloorFinishTitle>Floor Finish</FloorFinishTitle>
<FloorHeader>Floor</FloorHeader>
<FloorSubstractTitle>Floor Substrate</FloorSubstractTitle>
<FloorColorTitle>Floor Colour</FloorColorTitle>
<FloorSkirtingTitle>Skirting</FloorSkirtingTitle>
</FloorAttributeTitle>
<AspectAttributeItems>
<FloorAttributeItemBE>
<Description />
<Notes />
<ReferenceLink />
</FloorAttributeItemBE>
<FloorAttributeItemBE>
<FloorSubstract>Block pavement</FloorSubstract>
<FloorColor>Medium grey</FloorColor>
<FloorSkirting>N/A</FloorSkirting>
<FloorFinish>Ceramic tiles textured</FloorFinish>
<Description>test</Description>
<Notes />
<ReferenceLink />
</FloorAttributeItemBE>
</AspectAttributeItems>
</FloorAspect>
<WallAspect>
<WallAttributeTitle>
<Description>Description</Description>
<ReferenceLink>Reference Link</ReferenceLink>
<Notes>General Notes</Notes>
<WallHeader>Wall</WallHeader>
<WallNameTitle>Wall</WallNameTitle>
<WallFinishTitle>Wall finish</WallFinishTitle>
<WallColorTitle>Wall Colour</WallColorTitle>
</WallAttributeTitle>
<AspectAttributeItems>
<WallAttributeItemBE>
<WallName>Facade</WallName>
<WallFinish>Special</WallFinish>
<WallColor>TestValue</WallColor>
<Description>test</Description>
<Notes />
<ReferenceLink>test</ReferenceLink>
</WallAttributeItemBE>
</AspectAttributeItems>
</WallAspect>
<CeilingAspect>
<CeilingAttributeTitle>
<ReferenceLink>Reference Link</ReferenceLink>
<Notes>General Notes</Notes>
<AcousticsTitle>Acoustics</AcousticsTitle>
<CeilingInsertsTitle>Inserts</CeilingInsertsTitle>
<CeilingHeightTitle>Ceiling height</CeilingHeightTitle>
<CeilingHeader>Ceiling</CeilingHeader>
<CeilingSuspendedTitle>Suspended Ceiling</CeilingSuspendedTitle>
<CeilingRoomAcousticsTitle>Room acoustics</CeilingRoomAcousticsTitle>
<CeilingCoverageTitle>Coverage</CeilingCoverageTitle>
<CeilingTypeTitle>Type</CeilingTypeTitle>
<CeilingOthersTitle>Other</CeilingOthersTitle>
</CeilingAttributeTitle>
<AspectAttributeItems>
<CeilingAttributeItemBE>
<Notes />
<ReferenceLink />
</CeilingAttributeItemBE>
</AspectAttributeItems>
</CeilingAspect>
<EquipmentAspect>
<EquipmentAttributeTitle>
<ReferenceLink>Reference Link</ReferenceLink>
<Notes>General Notes</Notes>
<EquipmentHeader>Equipment</EquipmentHeader>
<EquipmentNameTitle>Equipment</EquipmentNameTitle>
<EquipmentQuantityTitle>Quantity</EquipmentQuantityTitle>
<EquipmentConnectionsTitle>Connections</EquipmentConnectionsTitle>
<Description>Description</Description>
</EquipmentAttributeTitle>
<AspectAttributeItems>
<EquipmentAttributeItemBE>
<EquipmentName>-</EquipmentName>
<EquipmentQuantity>100</EquipmentQuantity>
<EquipmentConnections>220V</EquipmentConnections>
<Description>test2</Description>
<Notes />
<ReferenceLink />
</EquipmentAttributeItemBE>
</AspectAttributeItems>
</EquipmentAspect>
</RoomReportBE>
<RoomReportBE>
</RoomReportBE>
</ArrayOfRoomReportBE>
Please change two things: first, <fo:region-after extent="10mm" region-name="footer-normal"> to <fo:region-after extent="10mm">. And second, change <fo:static-content flow-name="footer-normal"> to <fo:static-content flow-name="xsl-region-after">.
Related
i am trying to hide fo:table row or column lines based on the requirement from web application, so i used to set border-style="none" to fo:table-column or fo:table-row based on the need, but when i tried it,
either it creates dark lines in row's (if i hide column lines)
or creates dark lines in column's (if i hide row lines).
If column lines get hidden:
If row lines get hidden:
MY XSL:
<?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">
<xsl:template match="pages">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple"
page-height="8.5in" page-width="11in" margin-top=".5in"
margin-bottom=".5in" margin-left=".5in" margin-right=".5in">
<fo:region-body margin-top="2cm" margin-bottom="2cm" />
<fo:region-before extent="2cm" overflow="hidden" />
<fo:region-after extent="1cm" overflow="hidden" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple"
initial-page-number="1">
<fo:static-content flow-name="xsl-region-before">
<fo:block font-size="13.0pt" font-family="serif"
padding-after="2.0pt" space-before="4.0pt" text-align="center"
border-bottom-style="solid" border-bottom-width="1.0pt">
<fo:block>IF COLUMN LINES HIDED</fo:block>
</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:block font-size="12.0pt" font-family="sans-serif"
padding-after="2.0pt" space-before="2.0pt" text-align="center"
border-top-style="solid" border-bottom-width="1.0pt">
<xsl:text>Page</xsl:text>
<fo:page-number />
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="page-body" />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="page-body">
<fo:block text-align="center" break-before="page">
<fo:table table-layout="fixed" width="100%"
border-style="solid">
<fo:table-column border-style="solid"/>
<fo:table-column border-style="solid"/>
<fo:table-column border-style="solid"/>
<!-- For hiding column lines -->
<!-- <fo:table-column border-style="none"/> -->
<!-- <fo:table-column border-style="none"/> -->
<!-- <fo:table-column border-style="none"/> -->
<fo:table-header>
<xsl:apply-templates select="table-header" />
</fo:table-header>
<fo:table-body>
<xsl:apply-templates select="table-data" />
</fo:table-body>
</fo:table>
</fo:block>
</xsl:template>
<xsl:template match="table-header">
<fo:table-row keep-together.within-page="always"
border-style="solid">
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-one"></xsl:value-of>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-two"></xsl:value-of>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-three"></xsl:value-of>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template match="table-data">
<fo:table-row keep-together.within-page="always"
border-style="none">
<!-- For showing row lines -->
<!-- <fo:table-row keep-together.within-page="always" -->
<!-- border-style="solid"> -->
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-one"></xsl:value-of>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:if test="number(column-two) = number(column-two)">
<xsl:value-of select="format-number(translate(column-two, ',','.'), '#,###.##')"></xsl:value-of>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-three"></xsl:value-of>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
MY XML:
<?xml version="1.0" encoding="UTF-8"?>
<pages>
<page-body>
<table-header>
<column-one>Column One</column-one>
<column-two>Column Two</column-two>
<column-three>Column Three</column-three>
</table-header>
<table-data>
<column-one>One</column-one>
<column-two>5000</column-two>
<column-three>Three</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>5000</column-two>
<column-three>Three</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>0</column-two>
<column-three>Three</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>0</column-two>
<column-three>Four</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>2000</column-two>
<column-three>Four</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>1234</column-two>
<column-three>Five</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>5666</column-two>
<column-three>Five</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>5666</column-two>
<column-three>Five</column-three>
</table-data>
</page-body>
</pages>
I am using these xml and xsl files to generate PDF using apache fop, Is there any problem in my code?
Unfortunately, this sort of thing crops up from time to time in FO development involving FOP rendering.
For your answer, please see Section 6.9 of xmlgraphics.apache.org's FAQ re anti-aliasing and Acrobat.
Notice that if you play with the zoom factor in Acrobat, the problem will disappear/reappear depending on the setting.
Also note that if you try your example with RenderX (a.k.a XEP), this won't happen. They've apparently figured out (or never had) the problem.
One of the perils of trying to get away with a non-commercial FO product. (Not that something has to be commercial to be good, of course, but it's just fact that commercial FO processors are better and more powerful than FOP, though FOP is improving, albeit slowly.)
If you have to continue using FOP, make sure you're on the latest version (see this pin). Some important benefit to be had with 2.4.
ADDENDUM (Usage of SVG):
You can avoid this FOP bugginess by dynamically-built-out SVG markup.
Here's an example of the kind of markup you'd have to generate to get a PDF table by this method:
<fo:instream-foreign-object>
<svg:svg width="1000%" height="1000%">
<svg:g id='rowGroup' transform='translate(0, 0)' role="table">
<svg:text x='30' y='30' font-size='18px' font-weight='bold' fill='crimson' text-anchor='middle' role="row">
<svg:tspan role="columnheader" x='100'>Sales</svg:tspan>
<svg:tspan role="columnheader" x='200'>Expenses</svg:tspan>
<svg:tspan role="columnheader" x='300'>Net</svg:tspan>
</svg:text>
<svg:rect x='30' y='40' width='310' height='1' fill='black'/>
<svg:text x='30' y='30' font-size='18px' text-anchor='middle' role="row">
<svg:tspan id="q1" role="rowheader" x='30' dy='1.5em' font-weight='bold' fill='crimson' text-anchor='start'>Q1</svg:tspan>
<svg:tspan role="cell" x='100'>$223</svg:tspan>
<svg:tspan role="cell" x='200'>$195</svg:tspan>
<svg:tspan role="cell" x='300'>$28</svg:tspan>
</svg:text>
<svg:rect x='30' y='60' width='310' height='1' fill='black'/>
<svg:text x='30' y='50' font-size='18px' text-anchor='middle' role="row">
<svg:tspan id="q2" role="rowheader" x='30' dy='1.5em' font-weight='bold' fill='crimson' text-anchor='start'>Q2</svg:tspan>
<svg:tspan role="cell" x='100'>$295</svg:tspan>
<svg:tspan role="cell" x='200'>$263</svg:tspan>
<svg:tspan role="cell" x='300'>$32</svg:tspan>
</svg:text>
<svg:rect x='30' y='80' width='310' height='1' fill='black'/>
<svg:text x='30' y='70' font-size='18px' text-anchor='middle' role="row">
<svg:tspan id="q3" role="rowheader" x='30' dy='1.5em' font-weight='bold' fill='crimson' text-anchor='start'>Q3</svg:tspan>
<svg:tspan role="cell" x='100'>$951</svg:tspan>
<svg:tspan role="cell" x='200'>$232</svg:tspan>
<svg:tspan role="cell" x='300'>$719</svg:tspan>
</svg:text>
<svg:rect x='30' y='100' width='310' height='1' fill='black'/>
<svg:text x='30' y='90' font-size='18px' text-anchor='middle' role="row">
<svg:tspan id="q4" role="rowheader" x='30' dy='1.5em' font-weight='bold' fill='crimson' text-anchor='start'>Q4</svg:tspan>
<svg:tspan role="cell" x='100'>$823</svg:tspan>
<svg:tspan role="cell" x='200'>$175</svg:tspan>
<svg:tspan role="cell" x='300'>$648</svg:tspan>
</svg:text>
<svg:rect x='30' y='120' width='310' height='1' fill='black'/>
</svg:g>
</svg:svg>
</fo:instream-foreign-object>
I leave it to you to dynamicize the FO creation for your particular case, but this ought to teach you how to build tables this way.
You can easily achieve the effects you desire by drawing the borders as SVG polygons, which is where Kevin was going with this (although I believe he was speaking of the code inside the RenderX engine. My solution externalizes that via embedded SVG creation.) Of course, the <svg:rect> tag is a form of polygon, and that's what you'd use to render borders.
Remember to specify the SVG namespace on your <xsl:stylesheet> tag if you're going to attempt this.
xmlns:svg="http://www.w3.org/2000/svg"
Check out this recently merged patch (merged 2020-12-29), which seems to fix this problem for me:
https://issues.apache.org/jira/browse/FOP-2536 (Varying table border thickness in PDF output)
Revision 1884907: FOP-2536: Allow overpaint of PDF border
From the Apache FOP 2.6 you can to set the following parameter into the configuration file (by default fop.xconf):
<table-border-overpaint>true</table-border-overpaint>
This option may to make your borders thicker, but fix an issue:
https://xmlgraphics.apache.org/fop/faq.html#acrobat-anti-aliasing
Also this issue is registered as Chromium Pdf rendering bug:
https://bugs.chromium.org/p/chromium/issues/detail?id=500023
I have the xsl-fo template:
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master margin-right="1cm"
margin-left="2.7cm" margin-bottom="2cm" margin-top="2cm"
page-width="21.5cm" page-height="29.7cm" master-name="first">
<fo:region-body margin-right="1cm" margin-left="0cm" />
<fo:region-after region-name="xsl-region-after" display-align="before" extent="0.7in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="first">
<fo:static-content flow-name="xsl-region-after">
<fo:block text-align="center" font-size="10pt">
<fo:page-number />
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="rootElement" />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
All works excellent, but first page have a page number.
I do not need number on first page.
Thanks y'all!
You have to create a separate page-sequence-master for the first page, that does not include the page number. Then use a statement like this to specify which master will be used for each page of the book:
<fo:page-sequence-master master-name="chapter">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="page_first" page-position="first"/>
<fo:conditional-page-master-reference master-reference="page_even" odd-or-even="even"/>
<fo:conditional-page-master-reference master-reference="page_odd" odd-or-even="odd"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
(copied from one of my projects, so you'll have to adapt it to your structure)
I am using a program to generate a report. The program uses an XSL file to generate a PDF report. I am trying to create a custom XSL file.
In my example, I am trying to only generate a report for items that are 3.5" Floppy OR 5.25" Floppy (separately). In addition to this, I am trying to fit the results in two column per index card - for printing.
I'm not an XSL expert, but I've done a research, and found several possible solutions for what I'm trying to achieve (mainly this question) however the final results are always not what I want them to be - I may have a wrong concept of XSL parts, and I'd appreciate any input/pointers.
Here is a part from the XML:
?xml version="1.0" encoding="UTF-8" ?>
<catalog-objects xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="temp.xsd">
<software-item>
<item>Software</item>
<media-types>
<storage-medium>
<name>5.25" Floppy</name>
</storage-medium>
</media-types>
<title>Title 1</title>
</software-item>
<software-item>
<item>Software</item>
<media-types>
<storage-medium>
<name>3.5" Floppy</name>
</storage-medium>
</media-types>
<title>Title 2</title>
</software-item>
<software-item>
<item>Software</item>
<media-types>
<storage-medium>
<name>3.5" Floppy</name>
</storage-medium>
<storage-medium>
<name>5.25" Floppy</name>
</storage-medium>
</media-types>
<title>Title 3</title>
</software-item>
<software-item>
<item>Software</item>
<media-types>
<storage-medium>
<name>CD-Rom</name>
</storage-medium>
</media-types>
<title>Title 4</title>
</software-item>
Here is a part from the XSL I created:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo">
<xsl:import href="../../_stylesheets/pdf_desert.xsl" />
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes" />
<xsl:param name="versionParam" select="'1.0'" />
<xsl:template match="/">
<xsl:param name="size" select="count(catalog-objects/software-item)"/>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="Index Card 4X6"
page-height="4in" page-width="6in" margin-top="4mm"
margin-bottom=".65in" margin-left="4mm" margin-right="4mm">
<fo:region-body />
<fo:region-after />
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:variable name="individualFloppies" select="catalog-objects/software-item[(contains(media-types, '5.25') and not(contains(media-types, '3.5') or contains(media-types, 'ROM') or contains(media-types, 'Disc') or contains(media-types, 'CD') or contains(media-types, 'DVD') or contains(media-types, 'ray'))) or (contains(media-types, '3.5') and not(contains(media-types, '5.25') or contains(media-types, 'ROM') or contains(media-types, 'Disc') or contains(media-types, 'CD') or contains(media-types, 'DVD') or contains(media-types, 'ray')))]" />
<xsl:param name="size" select="$individualFloppies"/>
<xsl:for-each select="$individualFloppies[ceiling($size div 2) >= position()]">
<fo:page-sequence master-reference="Index Card 4X6">
<fo:static-content flow-name="xsl-region-after">
<fo:block font-size="{$fontSize}">
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="{$fontSize}">
<fo:table table-layout="fixed" width="100%" border-collapse="collapse">
<fo:table-column column-width="45%" />
<fo:table-column column-width="45%" />
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block text-align="right" font-size="8"><fo:inline font-weight="bold">ID </fo:inline><xsl:value-of select='format-number(archive-id, "000000")' /></fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="right" font-size="8"><fo:inline font-weight="bold">ID </fo:inline><xsl:value-of select='format-number(following::software-item[ceiling($size div 2)]/archive-id, "000000")' /></fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border-bottom="1px solid #000000">
<fo:block text-align="center" padding-top="0.2in" font-size="12" font-weight="bold">
<xsl:value-of select="title" />
</fo:block>
</fo:table-cell>
<fo:table-cell border-bottom="1px solid #000000">
<fo:block text-align="center" padding-top="0.2in" font-size="12" font-weight="bold">
<xsl:value-of select="following::software-item[ceiling($size div 2)]/title" />
</fo:block>
</fo:table-cell>
</fo:table-row>
The PDF report that is generated by the program is wrong because I also get cells with titles that do not match the filter. Also, sometimes at least one item title is not shown.
I tried "reverse engineering" to check whether my variable ($individualFloppies) filter isn't right, but when not using the two column approach I get good results however each in its own row.
It feels as if the following:: is causing the problem but it's just a guess.
I also tried following-sibling::, position() mod 2 = 1 as well as minimizing the filter I have.
If anyone can shed some light and tell me how far I am to what I am trying to achieve and where I am wrong I'd appreciate it very much.
As a first time poster here, I hope I provided all the important information.
EDIT:
I wasn't sure how to attach here the PDF files of the desired and the current output so I'll just ASCII it:
From the XML above, the desired output should only be one page:
╔════════════╤════════════╗
║ Title 1 │ Title 2 ║
╠════════════╪════════════╣
║ │ ║
║ │ ║
║ │ ║
╚════════════╧════════════╝
What I get after generating the report are two pages:
PAGE 1:
╔════════════╤════════════╗
║ Title 1 │ Title 3 ║
╠════════════╪════════════╣
║ │ ║
║ │ ║
║ │ ║
╚════════════╧════════════╝
PAGE 2:
╔════════════╤════════════╗
║ Title 2 │ Title 4 ║
╠════════════╪════════════╣
║ │ ║
║ │ ║
║ │ ║
╚════════════╧════════════╝
To put the logic in writing:
Since 'Title 1' is only '5.25" Floppy' and 'Title 2' is only '3.5" Floppy' they are the only two that should show up.
'Title 3' is '5.25" Floppy' but also is '3.5" Floppy' so it shouldn't show.
'Title 4' is a 'CD-Rom' so it shouldn't show as a column as well.
Writing this makes me realize that the filter I am using isn't working - odd considering I am using some similar filter on some different aspect and it does work.
I hope these edits are what was expected as "examples" and they clarify the issue more.
AFAICT, the problem here is with the expression:
<xsl:value-of select="following::software-item[ceiling($size div 2)]/title" />
Although you are in the context of looping over the filtered variable, the following:: axis is evaluated in the context of the source document. Here's a small stylesheet that demonstrates the problem in isolation as well as a possible solution:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="individualFloppies" select="catalog-objects/software-item[(contains(media-types, '5.25') and not(contains(media-types, '3.5') or contains(media-types, 'ROM') or contains(media-types, 'Disc') or contains(media-types, 'CD') or contains(media-types, 'DVD') or contains(media-types, 'ray'))) or (contains(media-types, '3.5') and not(contains(media-types, '5.25') or contains(media-types, 'ROM') or contains(media-types, 'Disc') or contains(media-types, 'CD') or contains(media-types, 'DVD') or contains(media-types, 'ray')))]" />
<out>
<wrong>
<xsl:for-each select="$individualFloppies">
<pair>
<left><xsl:value-of select="title" /></left>
<right><xsl:value-of select="following::software-item[1]/title"/></right>
</pair>
</xsl:for-each>
</wrong>
<right>
<xsl:for-each select="$individualFloppies">
<xsl:variable name="pos" select="position()" />
<pair>
<left><xsl:value-of select="title" /></left>
<right><xsl:value-of select="$individualFloppies[$pos+1]/title"/></right>
</pair>
</xsl:for-each>
</right>
</out>
</xsl:template>
</xsl:stylesheet>
With the help of michael.hor257k (thanks again!) I managed to add and change the necessary lines of code so it'll generate the report I was aiming for.
Here is the updated code (beginning from where the first change is applied):
<xsl:variable name="individualFloppies" select="catalog-objects/software-item[normalize-space(media-types)='3.5" Floppy' or normalize-space(media-types)='5.25" Floppy']" />
<xsl:param name="size" select="$individualFloppies"/>
<xsl:for-each select="$individualFloppies">
<xsl:variable name="pos" select="position()" />
<xsl:if test="position() mod 2 = 1">
<fo:page-sequence master-reference="Index Card 4X6">
<fo:static-content flow-name="xsl-region-after">
<fo:block font-size="{$fontSize}">
</fo:block>
</fo:static-content>
<!--Table Begins-->
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="{$fontSize}">
<fo:table table-layout="fixed" width="100%" border-collapse="collapse">
<fo:table-column column-width="2.5%" />
<fo:table-column column-width="45%" />
<fo:table-column column-width="2.5%" />
<fo:table-column column-width="2.5%" />
<fo:table-column column-width="45%" />
<fo:table-column column-width="2.5%" />
<fo:table-body>
<fo:table-row>
<fo:table-cell number-columns-spanned="3">
<fo:block text-align="right" font-size="8"><fo:inline font-weight="bold">ID </fo:inline><xsl:value-of select='format-number(archive-id, "000000")' /></fo:block>
</fo:table-cell>
<xsl:choose>
<xsl:when test="position() != last()">
<fo:table-cell number-columns-spanned="3">
<fo:block text-align="right" font-size="8"><fo:inline font-weight="bold">ID </fo:inline><xsl:value-of select='format-number($individualFloppies[$pos+1]/archive-id, "000000")' /></fo:block>
</fo:table-cell>
</xsl:when>
<xsl:otherwise>
<fo:table-cell number-columns-spanned="3"><fo:block></fo:block></fo:table-cell>
</xsl:otherwise>
</xsl:choose>
</fo:table-row>
<fo:table-row>
<fo:table-cell><fo:block></fo:block></fo:table-cell>
<fo:table-cell border-bottom="1px solid #000000">
<fo:block text-align="center" padding-top="0.2in" font-size="12" font-weight="bold">
<xsl:value-of select="title" />
</fo:block>
</fo:table-cell>
<fo:table-cell><fo:block></fo:block></fo:table-cell>
<fo:table-cell><fo:block></fo:block></fo:table-cell>
<xsl:choose>
<xsl:when test="position() != last()">
<fo:table-cell border-bottom="1px solid #000000">
<fo:block text-align="center" padding-top="0.2in" font-size="12" font-weight="bold">
<xsl:value-of select="$individualFloppies[$pos+1]/title" />
</fo:block>
</fo:table-cell>
</xsl:when>
<xsl:otherwise>
<fo:table-cell><fo:block></fo:block></fo:table-cell>
</xsl:otherwise>
</xsl:choose>
<fo:table-cell><fo:block></fo:block></fo:table-cell>
</fo:table-row>
Pointing out the updated lines:
Line 1: Cleaner and, I believe, better way to filter the data into the variable.
Lines 3-4: Implementing first part of michael.hor257k example
Line 5: Make the loop work only on the odd nodes (not sure my terminology is correct)
Lines 26-35/46-57: Implement the second part from michael.hor257k' example as well as check if the current position is the last one.
My xml looks like this:
<topics>
<topic name="topic1" />
<topic name="topic2" />
<topic name="topic3" />
<topic name="topic4" />
<topic name="topic5" />
<topic name="topic6" />
<topic name="topic7" />
</topics>
<supertopics>
<supertopic title="supertopic1" name="1;topic1;#2;#topic2;3;#topic3" />
<supertopic title="supertopic2" name="4;#topic4;#7;#topic7" />
<supertopic title="supertopic3" name="2;#topic2;#3;#topic3" />
<supertopic title="supertopic4" name="5;#topic5;#7;#topic7" />
<supertopic title="supertopic5" name="3;#topic3;#7;#topic7" />
<supertopic title="supertopic6" name="4;#topic4;#7;#topic7" />
<supertopic title="supertopic7" name="5;#topic5;#7;#topic7" />
<supertopic title="supertopic8" name="2;#topic2;#6;#topic6" />
<supertopic title="supertopic9" name="5;#topic6;#7;#topic7" />
<supertopic title="supertopic10" name="3;#topic3;#4;#topic4" />
</supertopics>
I basically want 1 supertopic per topic.So that means I have 7 topics and I want 7 most recent supertopics associated with it. I have date also with it through I m doing sorting but main thing is I want these 7 supertopics to be unique as there are multiple supertopics per topic.
So I want my output to be like this:
supertopic1 (topic1 is associated to supertopic1)
supertopic3 (topic2 is associated to supertopic1 but as its already there i want it to look for next supertopic its associated to)
supertopic5 (topic3)
supertopic2 (topic4)
supertopic4 (topic5)
supertopic8 (topic6)
supertopic6 (topic7)
I am using xsl 1.0
and I was trying to achieve it using but i couldn't find any way to do this:
<xsl:param name="FilteredAssets1">
<stopic></stopic>
<ttopic></ttopic>
</xsl:param>
<xsl:for-each select="topics/topic/#name">
<xsl:variable name="topicname">
<xsl:value-of select="."></xsl:value-of>
</xsl:variable>
<xsl:for-each select="/supertopics/supertopic[contains(#name,$topicname)]">
<xsl:if test="not(contains(msxsl:node-set($FilteredAssets1)/stopic,#title)) and not(contains(msxsl:node-set($FilteredAssets1)/ttopic,$programname))">
<stopic><xsl:value-of select="#title"></xsl:value-of></stopic>
<ttopic><xsl:value-of select="$programname"></xsl:value-of></ttopic>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vSupers"
select="/*/supertopics/supertopic"/>
<xsl:template match="/*">
<xsl:apply-templates select="topics/topic[1]"/>
</xsl:template>
<xsl:template match="topic">
<xsl:param name="pUsedSupers" select="/.."/>
<xsl:variable name="vNewSuper" select=
"$vSupers
[not(#title = $pUsedSupers/#title)
and
contains(concat(#name, ';'),
concat('#', current()/#name, ';')
)
]
[1]
"/>
<xsl:value-of select="concat('
', $vNewSuper/#title)"/>
<xsl:apply-templates select="following-sibling::topic[1]">
<xsl:with-param name="pUsedSupers"
select="$pUsedSupers | $vNewSuper"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML text (wrapped in with a single top element to be made a well-formed XML document and also with acorrection to what I think is a typo for supertopic1):
<t>
<topics>
<topic name="topic1" />
<topic name="topic2" />
<topic name="topic3" />
<topic name="topic4" />
<topic name="topic5" />
<topic name="topic6" />
<topic name="topic7" />
</topics>
<supertopics>
<supertopic title="supertopic1" name="1;#topic1;#2;#topic2;3;#topic3" />
<supertopic title="supertopic2" name="4;#topic4;#7;#topic7" />
<supertopic title="supertopic3" name="2;#topic2;#3;#topic3" />
<supertopic title="supertopic4" name="5;#topic5;#7;#topic7" />
<supertopic title="supertopic5" name="3;#topic3;#7;#topic7" />
<supertopic title="supertopic6" name="4;#topic4;#7;#topic7" />
<supertopic title="supertopic7" name="5;#topic5;#7;#topic7" />
<supertopic title="supertopic8" name="2;#topic2;#6;#topic6" />
<supertopic title="supertopic9" name="5;#topic6;#7;#topic7" />
<supertopic title="supertopic10" name="3;#topic3;#4;#topic4" />
</supertopics>
</t>
produces the wanted, correct result:
supertopic1
supertopic3
supertopic5
supertopic2
supertopic4
supertopic8
supertopic6
I'm using XSL-FO with Apache FOP to take a sexy looking XML file and output it as a PDF, however I'm having a really basic problem trying to get a particular bit of information (the address) to be positioned from the right of the page, I can force it over to the right by increasing the left attribute, but if I change my page size, orientation or margins this will immediately be useless.
Below is the code for the XSL, note the comment on line 23.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="all-pages"
page-height="297mm"
page-width="210mm"
margin-top="1cm"
margin-bottom="1cm"
margin-left="1cm"
margin-right="1cm" >
<fo:region-body margin-top="5cm" margin-bottom="1.1cm"/>
<fo:region-before extent="1cm"/>
<fo:region-after extent="5mm"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="default-sequence">
<fo:repeatable-page-master-reference master-reference="all-pages"/>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="default-sequence">
<fo:static-content flow-name="xsl-region-before" font-size="10pt" font-family="Helvetica" >
<!-- HERE'S MY PROBLEM, THE RIGHT ATTRIBUTE ISN'T BEHAVING ITSELF -->
<fo:block-container absolute-position="absolute" right="4cm" top="1cm" width="6cm" border-style="solid" border-width="1mm" >
<fo:list-block >
<fo:list-item>
<fo:list-item-label>
<fo:block></fo:block>
</fo:list-item-label>
<fo:list-item-body>
<fo:block>ABC</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item>
<fo:list-item-label>
<fo:block></fo:block>
</fo:list-item-label>
<fo:list-item-body>
<fo:block>123</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after" padding-top="2pt" border-top-style="solid" border-top-width="1pt" border-top-color="rgb(192,192,192)" font-size="10pt" font-family="Helvetica">
<fo:block></fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body" font-size="10pt" font-family="Helvetica">
<fo:block></fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
And as you can see by this screenshot the element isn't positioning correctly:
Any one know know why this is happening?
Bugger, looked at the FOP changelog and the two years between versions 0.95 and 1.0 made me think whether it was a bug, downloaded the new binaries and it's now positioning my element from the right.