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:Traslados>
<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" />
</cfdi:Traslados>

E.g.
IVA 16% = $109.20
IEPS 20 % = $91.00
IEPS 50% = $227.50

Could you please give me an example for that?

Regards,
alcaniAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
Here is the XSLT that will get you started

<?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:cfdi="foo"
	>

	<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:apply-templates></xsl:apply-templates>
				</fo:flow>
			</fo:page-sequence>
		</fo:root>
	</xsl:template>
	
	<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"/>
		</fo:block>
	</xsl:template>

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

			<fo:simple-page-master master-name="test-odd-page">
				<fo:region-body margin="2.5cm"/>
			</fo:simple-page-master>
			
			<fo:simple-page-master master-name="test-even-page">
				<fo:region-body margin="2.5cm"/>
			</fo:simple-page-master>
			
			<fo:simple-page-master master-name="test-empty-page">
				<fo:region-body margin="2.5cm"/>
			</fo:simple-page-master>
			
			<fo:page-sequence-master master-name="test-page">
				<fo:repeatable-page-master-alternatives>
					<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"/>
				</fo:repeatable-page-master-alternatives>
			</fo:page-sequence-master>

		</fo:layout-master-set>
	</xsl:template>

</xsl:stylesheet>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert BormansInformation ArchitectCommented:
you off course need to change this
xmlns:cfdi="foo"
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.