Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old March 20th, 2012, 01:10 AM
Authorized User
 
Join Date: Mar 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
Default 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?
 
Old March 20th, 2012, 04:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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:
aravindram87 (March 20th, 2012)
 
Old March 20th, 2012, 05:43 AM
Authorized User
 
Join Date: Mar 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
Default

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"
 
Old March 20th, 2012, 05:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old March 20th, 2012, 07:30 AM
Authorized User
 
Join Date: Mar 2012
Posts: 10
Thanks: 4
Thanked 0 Times in 0 Posts
Default

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
 
Old March 20th, 2012, 08:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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:
aravindram87 (March 20th, 2012)





Similar Threads
Thread Thread Starter Forum Replies Last Post
need your suggestions vic62 Joomla! 1 January 9th, 2009 01:33 AM
any suggestions? Acar BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 May 27th, 2008 07:19 AM
Suggestions lagoonblue Visual C++ 0 June 13th, 2005 07:18 PM
Java Design issue with UML and Design Patterns the_logical_way Apache Tomcat 0 May 31st, 2004 04:02 AM
Some suggestions richard.york Forum and Wrox.com Feedback 0 October 13th, 2003 01:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.