value-of is just going to pull in the value (text) associated with an xml tag. The svg tag will produce the svg output (image). You can put svg code into the xsl to generate a dynamic image based on data in the xml.
If you need the xsl tags themselves to be dynamic you can parse the input and mix it in from multiple sources if you're printing from custom embedded code. The xsl should be fed into the TransformerFactory.newTransformer method as a SAXSource which can be created from an InputSource which can be created from a ByteArrayInputStream which can be created from a simple byte[] array which can be created from a FileInputStream. Since you have the xsl file just sitting as a byte[] object in memory you can manipulate that however you want. You can read the file in one byte at a time looking for a particular byte sequence to mark where to add in code from a different file or read in the whole file at once then search the byte[] array for the byte point to insert other code. There may be a simpler way to substitute using tags in the xsl file but it sounds like this is what you may be trying to accomplish. -----Original Message----- From: Cristi Cioriia [mailto:[email protected]] Sent: Monday, January 17, 2011 10:57 AM To: [email protected] Subject: Re: Embedding SVG dynamically into fo file Thanks for such a quick reply. Using your feedback I was able to advance a little: if I replace "Some text " from your sample with <xsl:value-of select="svg"/> I can see in my report the svg that is generated. What I need though is that this code is executed so that in the PDF report I have the actual image, not its SVG representation. Any hint on how can I achieve that? Regards, Cristi > Cristi, > > In order to include SVG in your XSLT file, first declare the name > space as > follows: > > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:fo="http://www.w3.org/1999/XSL/Format" > xmlns:svg="http://www.w3.org/2000/svg"> > > > Then you can generate SVG as shown below: > > <fo:block> > <fo:instream-foreign-object span="all" > content-width="500pt" content-height="700pt" border-style="solid" > border-width="1" start-indent="0" margin-left="0"> > <svg > xmlns="http://www.w3.org/2000/svg" height="500" width="700"> > <rect x="50" y="50" height="400" > width="630" fill="none" stroke="black" stroke-width="1" /> > <text x="200" y="75" > style="font-family: ariel; fill:black; font-size:14; > font-weight:bold;">Some text</text> > </svg> > </fo:instream-foreign-object> > </fo:block> > > > Regards, > Jayant > > > > |------------> > | From: | > |------------> > >----------------------------------------------------------------------- ------------------------------------------------------------------------ ---| > |Cristi Cioriia<[email protected]> | > > >--------------------------------------------------------------------- > ---------------------------------------------------------------------- > -------| > |------------> > | To: | > |------------> > >----------------------------------------------------------------------- ------------------------------------------------------------------------ ---| > |<[email protected]> | > > >--------------------------------------------------------------------- > ---------------------------------------------------------------------- > -------| > |------------> > | Date: | > |------------> > >----------------------------------------------------------------------- ------------------------------------------------------------------------ ---| > |01/17/2011 10:10 AM | > > >--------------------------------------------------------------------- > ---------------------------------------------------------------------- > -------| > |------------> > | Subject: | > |------------> > >----------------------------------------------------------------------- ------------------------------------------------------------------------ ---| > |Embedding SVG dynamically into fo file | > > >--------------------------------------------------------------------- > ---------------------------------------------------------------------- > -------| > > > > > > Hi guys, > > I have ran into a dead end trying to generate a PDF report which > should contain SVG files generated on the fly, and I was hoping that I > can find some help here on how to proceed next. > At first, I embedded a svg file into a fo file using the > fo:instream-foreign-object and everything worked as expected, > generating the PDF report that I needed from the fo file by following > the examples from the FO website. > But then the pdf report that I have to generate uses as source data a > java object which contains a string property which provides the svg > file and looking at the example from the FOP website > http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/ > java/embedding/ExampleObj2PDF.java > > I created an xslt file like this: > > <xsl:template match="reportEntry"> > <fo:block> > > <fo:block> > <xsl:value-of select="title"/> > </fo:block> > > <fo:block> > <xsl:value-of select="description"/> > </fo:block> > > <fo:instream-foreign-object> > <xsl:value-of select="svg"/> > </fo:instream-foreign-object> > > </fo:block> > </xsl:template> > > But now, when I run the code I get the following exception: > > javax.xml.transform.TransformerException: > org.apache.fop.fo.ValidationException: Error(Unknown location): > fo:instream-foreign-object is missing child elements. > Required Content Model: one (1) non-XSL namespace child > > I have tried to find any help with google on how I can approach this, > but the only resources that I found use static resources as I did in > the first scenario, which is not enough for my use case. Can you point > me into the right direction on how to approach this? > > Thanks for your help, > Cristi > > -- > Cristian-Andrei Cioriia > Programator Java > > 1&1 Internet Development S.R.L. - Bucharest/Romania - Web Applications > Hosting Romania > 18 Mircea Eliade St > Sect 1, Bucharest > RO Bucharest, 012015 > Număr de telefon: +40 751 812 984 > [email protected] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > -- Cristian-Andrei Cioriia Programator Java 1&1 Internet Development S.R.L. - Bucharest/Romania - Web Applications Hosting Romania 18 Mircea Eliade St Sect 1, Bucharest RO Bucharest, 012015 Număr de telefon: +40 751 812 984 [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
