Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

xsl and plain text output  RSS feed

joe burkey
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all. I am just looking for some advice. My problem is that I have an xml doc that contains invoice information. eg <invoice_header> which contains name, address, current date etc. The document also contains multiple <invoice_line>tags which contains information on price, line description quantity and rate of tax etc. It also contains a <line_text>tag which can have multiple freeform line text. The <invoice_line> also contains a <deliver_address> tag.
My problem is that I have to write an xsl stylesheet which can format this information and the produce a plain text file for printing on a line printer.
And secondly, while I am formatting the text in the stylesheet I have to keep track of the amount of lines that have been printed and the amount of line space left on a page before scrolling down to a new page and inserting the header and then carrying on inserting the invoice lines and any associated delivery address or line text lines as well.
So basically my question is, Is there any examples of this on the web or am I mad and is there an easier way of doing this. Also bare in mind that I am also new to the xsl language.
Thanks in advance.
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe, unfortunately your name doesn't formally comply with our official policy on registered names. There has to be a blank between a first and last name. Please, take a moment and change your publicly displayed name.
Sorry for nitpicking!
It's not clear if your header contains the same information for all pages or not. In the former case it's probably easier to write XSLT that is only concerned with XML -> plain text transformation and then to feed its output to another program that would do pagination.
It's possible to do all the job with XSLT, but this will complicate its structure.
You can factor your header out in a separate template, like
<xsl:template name="header">
and then call it from the main template as
<xsl:call-template name="header"/>
How to count lines depends on the sctructure of your data, here is one example that uses position() function.
Or you could maintain line counter yourself (which isn't too elegant a solution)
<xsl:variable name="lineCounter" select="$lineCounter + 1"/>
Finally, here is a relevant discussion why you do not want to do pagination in XSLT
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!