0
votes

it's hard to find an exact title for my problem, but i'll try to describe what i need to do.

the basic process is creating xml-documents from measurements that i need to show to the users. for a fast view / preview i use html-output that will be shown in a browser. the complete document will be printed in pdf (user can choose pdf after preview). i'm using xsl-transformations to create html und xsl-fo output from xml data and then apache fop to create pdf output from xsl-fo output. this main process is working.

but now, i'm looking for a solution to handle 'formatted text' in xml. the xml includes some database fields, and here, it's not clear, which 'formatted text solution' i should use and how i could handle this in xsl to create htlm and pdf-output. my first idea was using html, so i can put the html from database into a CDATA Element in XML. to use the output directly in html, i could use this line of code <xsl:value-of select="formatted_text" disable-output-escaping="yes"/>

the question here: is it possible and how is it possible to transform the CDATA html to the xsl:fo syntax?

i also could use the opposite solution using xsl:fo tags in the database and CDATA Element and need to transform this to html tags.

but my supervisor now has the idea to use a markdown language to store formatted text in the database. as a result, the xml CDATA Element will contain markdown language and i need to transform this data using xsl-transformations into html and xsl-fo syntax. is this possible? if yes, i need a tip or a small example to get on the right way how to do this.

as a workaround, i think i can use c# to translate markdown language into html und xsl-fo output and put these output into my xml document, one tag with html data and a second tag with xsl-fo data. my supervisor is not happy with this idea, but at the moment, i have no better ideas.

do you have any tips or examples, how to transform CDATA element into html / xsl-fo?

1
Formatted text in XML sounds like XHTML or DocBook or DITA, I certainly wouldn't want to stuff markup escaped into a CDATA section. As for XSLT based conversion of Markdown to HTML, see github.com/MSmid/markdown2docbook, for instance. It doesn't really matter whether the XML has CDATA sections or other escape mechanisms, in the end you have a text node or plain string value.Martin Honnen

1 Answers

0
votes

If you want to store your information in a domain-specific language and then translate that to HTML and XSL-FO, you could look at the REx Parser Generator at https://www.bottlecaps.de/rex/. It can generate a parser as XSLT that you can integrate into your XSLT that generates the HTML and XSL-FO.

The focheck framework for validating XSL-FO files (https://github.com/AntennaHouse/focheck) uses a REx-generated parser for parsing property value expressions in attributes in the XSL-FO. parser-runner.xsl and axf-expression.xslt from https://github.com/AntennaHouse/focheck/tree/master/xsl may give you some ideas.