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 November 2nd, 2004, 04:04 AM
Registered User
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl:apply-templates on Variable containing xml

I have a external function that produces xml.
I put the xml from the function in a varible. Is it possible to apply templates on the variable, to process the xml its containing.

Is there any way to load xml, other than from a file that is possible with document()

Regards Daniel
 
Old November 2nd, 2004, 05:06 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by nexus5
 I have a external function that produces xml.
I put the xml from the function in a varible. Is it possible to apply templates on the variable, to process the xml its containing.
Not sure what you mean, if the variable is a nodeset then it sounds possible, can you show an example?

Quote:
quote:
Is there any way to load xml, other than from a file that is possible with document()
Use an extension function. What parser are you using?



--

Joe (Co-author Beginning XML, 3rd edition)
 
Old November 2nd, 2004, 05:15 AM
Registered User
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Joe!

Im useing the standard java parser.
example
-------
    <xsl:variable name="nr" select="./AutoListMovie/@nr" />
    <xsl:variable name="d" select="./AutoListMovie/@d" />
    <xsl:variable name="test" select="xhtmlStreaming:getLinkList($nr $d)" />
-------
I call a static java method (getLinkList) that does a database search and produces an xml. I put the result in a variable, but i guess its not a node set. Is it possible to generate a nodeset in any way, for other sources than from a file, like document() does?

Regards

Daniel


 
Old November 2nd, 2004, 07:13 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I'm not really up to speed on Java XML. You can use document function combined with a custom UriResolver that will intercept calls made by document and replace pass in your document.
Or you can make sure that $test is converted to a node-set using an extension function.
I'm sure Java parser has such a function but I don't know what it is, in Msxml2 it is msxsl:node-set().



--

Joe (Co-author Beginning XML, 3rd edition)
 
Old November 2nd, 2004, 01:38 PM
Registered User
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The node-set() extension isn't a part of standard java, which I'm useing. I know it is in saxon and other parsers, but i haven't got time to install, so i came up with a workaround that will have to do for now.

Tanks for your help!

Regards

Daniel
 
Old November 2nd, 2004, 02:01 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Anything that uses Java extension functions is likely to be processor dependent. However, if the function returns a node in a tree then it's likely you will be able to do apply-templates on it.

If the extension function is constructing a new tree, then a better bet might be to use the document() function, with some URI that your URIResolver can intercept to return a Source representing the new document.

Michael Kay

Michael Kay
http://www.saxonica.com/
 
Old November 2nd, 2004, 02:28 PM
Registered User
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Im pretty new to java, its my first application.

Michael, do you know what type of object my method should return? I've tried to return a Node and a NodeList-object, and then apply-template. None of them worked.

Do you know how to rewrite the URI-resolver?

Daniel
 
Old November 2nd, 2004, 03:57 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

As I say, it's processor dependent. I don't think you've said what processor you are using. And you really haven't given enough information for anyone to be able to see what you are doing wrong. You haven't even said what error message you are getting!

Writing a URIResolver is more likely to be portable across processors.

It would also be a good idea to explain what you are trying to achieve. I may not need extension functions at all.

Michael Kay

Michael Kay
http://www.saxonica.com/
 
Old November 2nd, 2004, 04:34 PM
Registered User
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When the code is under development its running on a powerbook G4 Mac. Live i guess it'll run on a Sun solaris 450.
I don't get any error messages at all, what i know of. It parses fine, with no exception, but the part this discussion is concerning doesn't display anything. I'll look into the logs more thoroughly tomorrow.

What I want to achieve.
When the parser comes to a specific xml-tag i want to include a list of links to movieclips. The information of which movieclips to include is not in the xml, Im parsing. Therefore i call a static java method that does a database search , builds an xml and returns a node to the tree. The tag that triggs the method tells the method from which department and how many links to fetch.

example
-------
    <xsl:variable name="nr" select="./AutoListMovie/@nr" />
    <xsl:variable name="dep" select="./AutoListMovie/@dep" />
    <xsl:variable name="test" select="xhtmlStreaming:getLinkList($nr $dep)" />
-------

Lets say the java-method returns something that is parseble. How do i do an apply-template on the tree?
 
Old November 4th, 2004, 02:55 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

?? stupid guess:
<xsl:apply-templates select="$test"/> or
<xsl:apply-templates select="document($test)"/>

won't work on xslt 1.0






Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
xsl:apply-templates select problem harapraveen XSLT 2 October 22nd, 2007 08:05 AM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
Doubt in XPATH synax in <xsl:apply-templates > rajatake XSLT 3 May 4th, 2006 06:30 AM
xsl:apply-templates - Pls help me out imme Avinash XSLT 1 November 13th, 2003 03:18 AM





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