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 December 12th, 2011, 03:53 PM
Authorized User
 
Join Date: Apr 2011
Posts: 22
Thanks: 4
Thanked 0 Times in 0 Posts
Default XML as param to XSLT

Hi All,
I am using Saxon 6. I have a created a XML as string in java and need this as a param in my XSL. Since this is on Saxon 6, I am unable to use saxon:parse (which is introduced in saxon 7).

What is the equivalent on saxon 6? Or how do i recreate the same functionality?

I tried passing the XML as string, stream source, stream result etc. In all theses cases (except String),when i print the value of the param I get the toString() of the object instead of the XML.

Any help is appreciated.
 
Old December 12th, 2011, 07:29 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First point: why are you sticking with Saxon 6? There are few good reasons for doing this.

Second point: you have to parse the lexical XML to a tree in the Java code, and then pass the resulting node (root of the tree) to Saxon.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old December 13th, 2011, 12:05 AM
Authorized User
 
Join Date: Apr 2011
Posts: 22
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Thanks Kay.

To your first point, Are you saying that there are good reasons to stay with Saxon6? We are considering an upgrade to 8 but not in the next four months.

I tried your solution. My code looks something like this:
Code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document document = builder.parse(new InputSource(new StringReader(result1.getWriter().toString())));
transformer2.setParameter("param11", document.getDocumentElement());
and in my XSL,
Code:
<xsl:param name="param11" />
<xsl:template match="/">
     <xsl:message><xsl:value-of select="concat('name: ',$param11/Root/@Name)" /></xsl:message>
</xsl:template>
But this gives me the following errror:
Error at xsl:value-of on line 10 of file:/Data.xsl:
The value is not a node-set
javax.xml.transform.TransformerException: The value is not a node-set
at com.icl.saxon.style.StyleElement.styleError(StyleE lement.java:818)
at com.icl.saxon.style.StyleElement.processChildren(S tyleElement.java:645)
at com.icl.saxon.style.XSLMessage.process(XSLMessage. java:87)

I also tried using exslt:node-set() around the param, but got a similar error(exslt:node-set(): argument must be a node-set or tree)

Can you please tell me where i am going wrong?

Last edited by imshriram; December 13th, 2011 at 02:17 AM..
 
Old December 13th, 2011, 06:12 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Are you saying that there are good reasons to stay with Saxon6?

On the contrary, I said there are very few good reasons to stay with Saxon6. About the only one I can think of is that your system works OK, meets all its requirements, and you have no need to make any changes.

>The value is not a node-set

I'm sorry, but Saxon6 is so long ago that I have no memory of what the rules are for passing parameters to a stylesheet - I would have to look it up in the documentation, which you can do equally well yourself.

Generally though (and this remains true with Saxon today) it's not a good idea to construct a DOM just for Saxon to use it. It's much better to let Saxon construct the tree itself, in its own optimized format. Instead of passing a DOM node as the stylesheet parameter, pass a URI, and within the stylesheet, call the document() function on that URI; or if you are starting from lexical XML in a string, use the Saxon APIs to construct a TinyTree.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old December 13th, 2011, 01:40 PM
Authorized User
 
Join Date: Apr 2011
Posts: 22
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Thanks Kay, as per your advice, we are writing the java output ina file and reading it as a document() in the XSL.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding xml-html transformation of an xml string using xslt and javascript suprakash444 XSLT 1 January 12th, 2009 01:23 AM
insert data param into xml from external file alexshiell XSLT 0 January 24th, 2006 01:47 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
passing param to XSLT Dangerous Dave XSLT 0 April 30th, 2004 07:46 PM





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