Subject: Re: [xsl] Parameter evaluation after use of document() From: Yves Forkl <Yves.Forkl@xxxxxxx> Date: Mon, 29 Jul 2002 22:27:17 +0200 |
Hi Oleg, Oleg Tkachenko wrote: > Yves Forkl wrote: > > > I am wondering why the XSLT code below doesn't work. Xalan-J dies with > > the (not very helpful) errors mentioned below as soon as it tries to > > get the value of "filename_base" in the second last line in the > > stylesheet excerpt. > > > <xsl:apply-templates > > select="document(concat($filename_base, '.xml'))" > > mode="info_mode"> > > Applying templates directly to a result of document() function can be > dangerous sometime due to the fact that the result is always root node > and template for "/" is in use. Without a mode it could cause infinite > looping, in your case you probably don't have template for root node in > info_mode mode and built-in template as usual loses your parameter. > Try to add some location path after document() function to eliminate > built-in templates processing as they don't pass parameters. I followed your suggestion exactly (see updated stylesheet excerpt below): now I only receive one type of error (InvocationTargetException), occurring where I'm calling the template on the other input document's content while trying to pass a parameter. Even indicating the document's root _element_ didn't change the situation; anyway, I would prefer a generic template like it can be seen below. I also added an info_mode template for the root of that document that also passes the parameter (see below), but it didn't change anything. How can I get the parameter through to the template which is processing my "side" input document? > But anyway it's perfectly legal xslt stylesheet and xalan shouldn't die > on it, probably you have found a bug. So, is there some Xalan expert out there to tell if the fatal error after "loosing" all parameters when reading from document() might be a Xalan bug? (Version: Xalan-Java 2.2.D13.) I join the updated versions of my snippets for completeness. Cheers, Yves ++++++++++ content of file "Chapter_1.xml" ++++++++++ <?xml version="1.0" encoding="iso-8859-1"?> <!-- ... --> <!-- ... --> <chapter id="Chapter1_ID"> <title>My First Chapter</title> ... </chapter> ++++++++++ excerpt of stylesheet ++++++++++ <!-- value of $type is not relevant --> <!-- process all element nodes of type $type --> <xsl:for-each select="key('select_nodes_by_type', $type)"> <xsl:call-template name="generic_info_template"> <!-- extract the text node of the each element node of type $type --> <xsl:with-param name="filename_base" select="text()"/> <!-- SUPPOSE: 1st run: $filename_base = "Chapter_1" --> </xsl:call-template> </xsl:for-each> <!-- apply appropriate info_mode templates to file contents --> <xsl:template name="generic_info_template"> <xsl:param name="filename_base"/> <!-- read in file contents and process them in info_mode --> <xsl:apply-templates select="document(concat($filename_base, '.xml'))/*" mode="info_mode"> <!-- hand the param to the called template --> <xsl:with-param name="filename_base" select="$filename_base"/> </xsl:apply-templates> </xsl:template> <!-- dummy template for root node of included document --> <xsl:template match="/" mode="info_mode"> <xsl:apply-templates mode="info_mode"> <xsl:with-param name="filename_base" select="$filename_base"/> </xsl:apply-templates> </xsl:template> <!-- write out info specifically for chapter nodes --> <xsl:template match="chapter" mode="info_mode"> <xsl:param name="filename_base"/> <xsl:text>This chapter's title: </xsl:text> <xsl:value-of select="title"/> <xsl:text> This chapter's filename base: </xsl:text> <xsl:value-of select="$filename_base"/> </xsl:template> ++++++++++ fatal error messages by Xalan-J ++++++++++ (Location of error unknown)XSLT Error (javax.xml.transform.TransformerException) : java.lang.reflect.InvocationTargetException XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Parameter evaluation after us, Joseph Kesselman | Thread | Re: [xsl] Parameter evaluation afte, Oleg Tkachenko |
Re: [xsl] XML/XSLT Problem, G. Ken Holman | Date | [xsl] ANN: Web XML Editor/Menu, James Fuller |
Month |