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 13th, 2005, 08:02 AM
Registered User
 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default xslt document() function problem with servlet

Hi!

I'm using xslt 1.0 (xalan) on a servlet that transforms xml
to html. The xsl file uses document() function to access a
xml file on the local file system (both files are under
the webapp directory in question).

When running the transformation from the command line, everything
works just fine. Not so when running it from the servlet.

I have the following in the xsl file:

    <xsl:param name="foo">
        <xsl:apply-templates select="document('../dir1/file.xml')" mode="bar"/>
    </xsl:param>

    <xsl:template match="root_node" mode="bar">
        <xsl:text>Hello World!</xsl:text>
        <xsl:for-each select="//*">
            <xsl:if test="@id = $req_id">
                ....
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

The funny thing (at least to a newbie like me) is that the "Hello World!"
gets printed, but the rest of the "root_node" template does nothing. Isn't
the fact that the template gets called a sign that the root node of the file
file.xml was found (which is root_node)? So the document function did find
the correct file, right?

I have set systemID's in Java to point to the directories containing the xml and xsl
files (in the form of 'file:///dir/dir...').

Thanks

 
Old December 13th, 2005, 08:22 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Perhaps the value of $req_id isn't being passed in correctly?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 13th, 2005, 09:19 AM
Registered User
 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mhkay
 Perhaps the value of $req_id isn't being passed in correctly?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
I did some testing, and what I can tell the parameter is correct. I used <xsl:value-of select="$req_id"/> inside the root_node template and the output was what it was supposed to be.

For some reason, when run from the servlet, the processing of the template stops in <xsl:for-each select="//*">... As I said, when run from the console everything works fine.

I guess the problem isn't in the xslt(?) (or in the document() call) cause it works from the console, but something in the servlet code I have missed. Perhaps something silly... I have to investigate more.

 
Old December 20th, 2005, 10:34 AM
Registered User
 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok,

The problem had to do with the xslt that comes bundled with Java 1.4.2_05 (com.sun.org.apache.xalan.internal.xsltc.trax.Tran sformerFactoryImpl). For some reason my xsl:for-each didn't agree with it. Using Xalan from the Apache XML project everyting works just fine.






Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt document function.. maddukuri XSLT 8 May 16th, 2008 06:31 AM
Document Function Atribute bonekrusher XSLT 2 September 26th, 2006 05:44 PM
Document ( ) Function bonekrusher XSLT 5 August 4th, 2006 08:01 AM
How to use document() function jacob XSLT 8 November 30th, 2005 08:58 PM
xslt 2.0 document function jkmyoung XSLT 2 November 18th, 2004 03:21 PM





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