• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

apache fop to transform an XML file to get a pdf using XSLT

Hi experts,

I’m using apache fop to transform an XML file to get a pdf using XSLT.

I have this node and I would like to display the information in the pdf file in 3 different rows

<cfdi:Traslado impuesto="IVA" tasa="16.00" importe="109.20" />
<cfdi:Traslado impuesto="IEPS" tasa="20.00" importe="91.00" />
<cfdi:Traslado impuesto="IEPS" tasa="50.00" importe="227.50" />

IVA 16% = $109.20
IEPS 20 % = $91.00
IEPS 50% = $227.50

Could you please give me an example for that?

  • 2
1 Solution
Geert BormansInformation ArchitectCommented:
Here is the XSLT that will get you started

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"

	<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>

	<xsl:template match="/">
		<fo:root font-family="Helvetica">
			<!-- layout master set -->
			<xsl:call-template name="layout-master-set"/>
			<fo:page-sequence master-reference="test-page">
				<fo:flow flow-name="xsl-region-body">
	<xsl:template match="cfdi:Traslado">
		<fo:block font-size="12pt" font-weight="bold">
			<xsl:value-of select="@impuesto"/>
			<xsl:text> </xsl:text>
			<xsl:value-of select="@tasa"/>
			<xsl:text>% = $</xsl:text>
			<xsl:value-of select="@importe"/>

	<xsl:template name="layout-master-set">

			<fo:simple-page-master master-name="test-odd-page">
				<fo:region-body margin="2.5cm"/>
			<fo:simple-page-master master-name="test-even-page">
				<fo:region-body margin="2.5cm"/>
			<fo:simple-page-master master-name="test-empty-page">
				<fo:region-body margin="2.5cm"/>
			<fo:page-sequence-master master-name="test-page">
					<fo:conditional-page-master-reference master-reference="test-even-page" blank-or-not-blank="not-blank" odd-or-even="even"/>
					<fo:conditional-page-master-reference master-reference="test-odd-page" blank-or-not-blank="not-blank" odd-or-even="odd"/>
					<fo:conditional-page-master-reference master-reference="test-empty-page" blank-or-not-blank="blank"/>



Open in new window

Geert BormansInformation ArchitectCommented:
you off course need to change this
in the actual document namespace

It would help if you posted wellformed or vald XML snippets for testing
I had to make up a namespace to get it going
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now