jawadde Posted February 26, 2012 Share Posted February 26, 2012 Hi, I'm trying to build a little document generation tool.The tool consists of 3 files: data.xml (this is a datafile containing data to be merged in the end document) Docgen.xsl (xsl styleshet that is used for the transformation. Paragraphs.xml (xml file containing all possible paragraphs for the document) The paragraphs of the html document are stored in an XML file as small (reusable) html snippets. However these paragraphs also contain XSL statements like <xsl:value-of...> where I'm trying to do value replacement from the original data.xml file. Below you find an example of the 3 files I use. The problem is that I don't seem to be able to do the replacement of the <xsl:value-of> statements that reside inside the paragraphs. they simply do not get recognised and are ignored in the output file.In the real world version there will be more complex situations, where I want to include <xsl:for-each> and other statements in the paragraphs. So I'm trying to build dynamic xsl, that is interpreted, although it does not reside in the xsl stylesheet. Anybody any idea how I can accomplish this in XSLT 1.0? Thanks data.xml <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="Docgen.xsl"?><data><type>CLD</type><validationdate>27/2/2012</validationdate><description>Real nice title</description></data> Paragraphs.xml: please note the embedded xsl statement in the second paragraph. <?xml version="1.0" encoding="UTF-8"?><paragraphs><paragraph code="CLD">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque interdum.</paragraph><paragraph code="CLD"><H2>Proin urna sem, <xsl:value-of select="/data/validationdate"/> luctus quis aliquet non </H2></paragraph><paragraph code="CLD">Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Integer auctor, dolor ut tincidunt semper, mauris tortor mollis libero, ut pretium.</paragraph><paragraph code="PKS">Curabitur massa risus, tristique vel mollis a, tempus id ipsum. Curabitur ac dolor tellus. ###### sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus.</paragraph><paragraph code="PKS">Vivamus egestas scelerisque lobortis. Aliquam sollicitudin metus.</paragraph></paragraphs> Docgen.xsl <?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"><xsl:variable name="P" select="document('Paragraphs.xml')"/><xsl:variable name="D" select="/data/type"/><xsl:template match="/"><html> <head> <title></title> </head> <body> <h1><center><xsl:value-of select="/data/description"/></center></h1> <table> <ol type="1"> <xsl:for-each select="$P/paragraphs/paragraph[@code=$D]"> <tr> <td><li><xsl:value-of select="." disable-output-escaping="yes"/></li></td> </tr> </xsl:for-each> </ol> </table> </body></html></xsl:template></xsl:stylesheet> Link to comment Share on other sites More sharing options...
boen_robot Posted February 26, 2012 Share Posted February 26, 2012 You can't do what you want in one pass... but you could use XSLT to generate another XSLT that uses the paragraph templates, and then apply that XSLT over the original data set. It might be a good idea to replace the pseudo stuff like "<xsl:" with actual XSLT elements (including a namespace declaration at the top). Link to comment Share on other sites More sharing options...
jawadde Posted February 27, 2012 Author Share Posted February 27, 2012 Thanks Boen_robot for your answer.Would it be possible to do in XSLT 2.0 or maybe using some of the extension (EXSLT, etc..)If so, could you point me in the right direction? Thanks. Link to comment Share on other sites More sharing options...
boen_robot Posted February 29, 2012 Share Posted February 29, 2012 If there is a way, I don't know how.But generating XSLT by using XSLT isn't that bad. Two efficient XSLT transformations could be more efficient than a single non efficient XSLT transformation. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.