Skip to content

Instantly share code, notes, and snippets.

@passsy
Last active February 24, 2025 18:30
Show Gist options
  • Save passsy/e87a3873d41865f33033203fa6337ffe to your computer and use it in GitHub Desktop.
Save passsy/e87a3873d41865f33033203fa6337ffe to your computer and use it in GitHub Desktop.
How to use xrechnung-visualization

How to use xrechnung-visualization

1. Install Ant

Install brew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Then install ant using brew

brew install ant

2. Run ant

Go into xrechnung-visualization repo and run ant (may take a few minutes)

cd xrechnung-visualization
ant

The ant scripts will download all tools required to execute the transformations

Once download, you'll find a lot of files in the newly created /build folder.

3. Transform CIUS XRechnung to HTML or PDF

We're using SAXON, a open-source XSLT processor (saxon9he.jar) which was downloaded by the ant script. It uses the xsl style sheets in the repository to style the XML files.

You can run java -jar lib/saxon9he.jar to get more informations how it works

First we have to convert the XML first into the intermediate .xr format.

java -jar lib/saxon9he.jar -s:path/to/Rechnung.xml -xsl:src/xsl/ubl-invoice-xr.xsl -o:out/Rechnung.xr

Generate HTML

java -jar lib/saxon9he.jar -s:out/Rechnung.xr -xsl:src/xsl/xrechnung-html.xsl -o:out/Rechnung.html

Generate PDF

java -jar lib/saxon9he.jar -s:out/Rechnung.xr -xsl:src/xsl/xr-pdf.xsl -o:out/Rechnung.pdf 
@ryder-hook
Copy link

Did not work anymore. Creation of PDF did not work. PDF file is corrupted. Anyway HTML file creation worked.

@rstrajher-omnizon
Copy link

If you use xr-pdf.xsl, the resulting file seems to be XSL-FO, and then you can use fop directly to create a PDF from it.

  1. java -jar lib/saxon9he.jar -s:path/to/Rechnung.xml -xsl:src/xsl/ubl-invoice-xr.xsl -o:out/Rechnung.xr
  2. java -jar lib/saxon9he.jar -s:out/Rechnung.xr -xsl:src/xsl/xr-pdf.xsl -o:out/Rechnung.fo
  3. fop -fo out/Rechnung.fo -pdf out/Rechnung.pdf

Maybe we're missing something, but this worked for me.

@afh
Copy link

afh commented Feb 24, 2025

Here's a Makefile with which html and pdf can easily be generated:

  • Place the contents below into a Makefile in the xrechnung-visualization repo
  • Copy your invoice xml files into the xrechnung-visualization repo
  • Generate HTML from a Rechung-001.xml using: make Rechnung-001.html
  • Generate PDF from a Rechung-001.xml using: make Rechnung-001.pdf
%.xr: %.xml
	java \
		-jar lib/saxon-he-10.6.jar \
		-xsl:src/xsl/ubl-invoice-xr.xsl \
		-s:$< \
		-o:$@

%.html: %.xr
	java \
		-jar lib/saxon-he-10.6.jar \
		-xsl:src/xsl/xrechnung-html.xsl \
		-s:$< \
		-o:$@

%.fo: %.xr
	java \
		-jar lib/saxon-he-10.6.jar \
		-xsl:src/xsl/xr-pdf.xsl \
		-s:$< \
		-o:$@


%.pdf: %.fo
	fop -fo $< -pdf $@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment