 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 20th, 2012, 01:10 AM
|
|
Authorized User
|
|
Join Date: Mar 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Design suggestions
Hi Guys,
I have these two lines of code:
transformer = factory.newTransformer(xslSource);
transformer.transform( xmlSource, new StreamResult( baos ) );
My question is about the xml source. I inject the values for all the variables and parameters variables defined in the xsl from the java class where I do the transformation to PDF. In my case all the values that are present on the generated PDF are dynamic. I can't give the values in the XML.
So my XML structure is like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
</root>
And in my xsl, for formatting I use <fo:> tags and wherever I need to display values, I do something like this:
<xsl:template match="root">
.
.
.
.
<fo:table-cell border="solid 0px black"
text-align="left">
<fo:block font-size="8pt">
<xsl:value-of select="java:getValue($ref)"/>
</fo:block>
</fo:table-cell>
.
.
.
</xsl:template>
I am little concerned about this design because the two XSL books I read, always have a xml in conjunction to a xsl and in my case, the xml has no role to play. Is this correct?
|
|

March 20th, 2012, 04:33 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
It's a lilttle unorthodox to use XSLT in this way, but there's absolutely nothing wrong with it. In fact, it was for this kind of use case that XSLT 2.0 introduced the ability to run a stylesheet starting with a named template as the entry point, so there is no longer any need to have a dummy XML file as input.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|

March 20th, 2012, 05:43 AM
|
|
Authorized User
|
|
Join Date: Mar 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Thank you Michael,
I am very much pleased to get the "green-signal" from you. Could you please throw some light on this - "XSLT 2.0 introduced the ability to run a stylesheet starting with a named template as the entry point"
|
|

March 20th, 2012, 05:54 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Sorry, I don't see what's dark about my statement. XSLT 2.0 allows you to fire off a transformation in effect by doing a "call template" rather than an "apply templates". The way this is achieved will depend on the API you are using. Of course, it won't work from an XSLT 1.0 API such as JAXP.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

March 20th, 2012, 07:30 AM
|
|
Authorized User
|
|
Join Date: Mar 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
Sorry if my question was very lame. I have started learning XSLT quite recently. I tried changing the xslt version in the namespace as <xsl:stylesheet version="2.0" and replaced the template to a named-template.
Changed <xsl:template match="root"> to <xsl:template name="main">. When I run the transformer, I get the follwing exception,
[ERROR] Logger not set
[WARNING] Screen logger not set - Using ConsoleLogger.
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] building formatting object tree
[INFO] setting up fonts
[INFO] Parsing of document complete, stopping renderer
[Fatal Error] :-1:-1: Premature end of file.
Exception in thread "Main Thread" org.apache.fop.apps.FOPException: Premature end of file.
at org.apache.fop.apps.Driver.render(Driver.java:503)
at org.apache.fop.apps.Driver.run(Driver.java:565)
at apachefop.java.XslToPdf.convert(XslToPdf.java:63)
at apachefop.java.XslToPdf.main(XslToPdf.java:27)
Is there something else I should change or is my xsl processor not supporting it. My XSL processor is org.apache.xalan.processor.TransformerFactoryImpl
|
|

March 20th, 2012, 08:11 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Apache Xalan does not support XSLT 2.0. For that you need Saxon.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|
 |