[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
I'm confused about when a parameter contains a result tree fragment and when it contains a node set. I get similar results (an error) in both Xalan and InstantSaxon, so I suspect the difficulty is caused by my confusion rather than a bug in the XSLT processors. (I'm running Xalan 1.2D01 with Sun's JDK 1.3 and Client Hotspot, and InstantSaxon 5.4.1.)
As far as I can tell, the error appears to arise on the expression "$step_data/@Instance" where step_data is a parameter passed to the template AND the template has been invoked with an <xsl:apply-templates select="document('tree_error1.xml')"><xsl:with-param name="step_data" select="$step_data"/></xsl:apply-templates>. step_data is a variable that, I believe, contains a node set: <xsl:variable name="step_data" value="."/>. If I invoke "$step_data/@Instance" in the invoking template (before the apply-templates call), the expression returns what I expected, which is why I believe that the variable is indeed a node set.
My understanding of variables and parameters (from reading the XSLT spec and Mike Kay's excellent book) is that the data type of a variable or parameter will always be a node-set if the value of the variable/parm was set with a SELECT expression, and the data type would be a result tree fragment only if the value were set with a non-empty template body. Is this correct? If it is, I would expect the parameter step_data to be a node-set, not a result tree fragment.
Here's the XSL stylesheet:
<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="suspended_step">
<xsl:variable name="step_data" select="."/>
<HTML>
<HEAD>
<TITLE><xsl:value-of select="@Instance"/></TITLE>
</HEAD>
<BODY>
<H1>Value of $step_data/@Instance is /<xsl:value-of select="$step_data/@Instance"/>/</H1>
<H1>Count of step_data before template invocation
is <xsl:value-of select="count($step_data)"/></H1>
(Invoking template)
<xsl:apply-templates select="document('tree_error2.xml')">
<xsl:with-param name="step_data" select="$step_data"/>
</xsl:apply-templates>
(Returned from template)
</BODY>
</HTML>
</xsl:template>
<xsl:template match="top_element">
<xsl:param name="step_data"/>
<H1>Value of $step_data/@Instance is /<xsl:value-of select="$step_data/@Instance"/>/</H1>
<H1>Value of string($step_data) is /<xsl:value-of select="string($step_data)"/>/</H1>
<H1>Count of $step_data is <xsl:value-of select="count($step_data)"/></H1>
</xsl:template>
</xsl:stylesheet>
Line #16, Column #64: xsl:apply-templates, select='document('tree_error2.xml')':
org.apache.xalan.xpath.dtm.DTMProxy@7bd9f2
Line #0, Column #0: xsl:template match='/'
Line #24, Column #37: xsl:template match='top_element'
STARTELEMENT: H1
CHARACTERS: Value of $step_data/@Instance is /
XPATH: Can not convert #RTREEFRAG to a NodeList!
Xalan: was not successful.
XSLProcessor: done
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Question about result tree fragments vs. node sets in parameters
Subject: Question about result tree fragments vs. node sets in parameters From: jim hopp <jhopp@xxxxxxxxxxx> Date: Sat, 26 Aug 2000 14:33:05 -0700 |
I'm confused about when a parameter contains a result tree fragment and when it contains a node set. I get similar results (an error) in both Xalan and InstantSaxon, so I suspect the difficulty is caused by my confusion rather than a bug in the XSLT processors. (I'm running Xalan 1.2D01 with Sun's JDK 1.3 and Client Hotspot, and InstantSaxon 5.4.1.)
As far as I can tell, the error appears to arise on the expression "$step_data/@Instance" where step_data is a parameter passed to the template AND the template has been invoked with an <xsl:apply-templates select="document('tree_error1.xml')"><xsl:with-param name="step_data" select="$step_data"/></xsl:apply-templates>. step_data is a variable that, I believe, contains a node set: <xsl:variable name="step_data" value="."/>. If I invoke "$step_data/@Instance" in the invoking template (before the apply-templates call), the expression returns what I expected, which is why I believe that the variable is indeed a node set.
My understanding of variables and parameters (from reading the XSLT spec and Mike Kay's excellent book) is that the data type of a variable or parameter will always be a node-set if the value of the variable/parm was set with a SELECT expression, and the data type would be a result tree fragment only if the value were set with a non-empty template body. Is this correct? If it is, I would expect the parameter step_data to be a node-set, not a result tree fragment.
Here's the XSL stylesheet:
<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="suspended_step">
<xsl:variable name="step_data" select="."/>
<HTML>
<HEAD>
<TITLE><xsl:value-of select="@Instance"/></TITLE>
</HEAD>
<BODY>
<H1>Value of $step_data/@Instance is /<xsl:value-of select="$step_data/@Instance"/>/</H1>
<H1>Count of step_data before template invocation
is <xsl:value-of select="count($step_data)"/></H1>
(Invoking template)
<xsl:apply-templates select="document('tree_error2.xml')">
<xsl:with-param name="step_data" select="$step_data"/>
</xsl:apply-templates>
(Returned from template)
</BODY>
</HTML>
</xsl:template>
<xsl:template match="top_element">
<xsl:param name="step_data"/>
<H1>Value of $step_data/@Instance is /<xsl:value-of select="$step_data/@Instance"/>/</H1>
<H1>Value of string($step_data) is /<xsl:value-of select="string($step_data)"/>/</H1>
<H1>Count of $step_data is <xsl:value-of select="count($step_data)"/></H1>
</xsl:template>
</xsl:stylesheet>
Here's the XML that the stylesheet is processing: <?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?> <suspended_step Instance="3088.3876"> <Instance> <RI DID="hello" IID="1461.5152" /> </Instance> </suspended_step>
Here's the contents of tree_error2.xml: <?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?> <top_element Instance="3088.3876"> <Instance> <RI DID="hello" IID="1461.5152" /> </Instance> </top_element>
Here's the InstantSaxon output: C:\DVLP\docs>\saxon\saxon tree_error.xml tree_error.xsl <HTML> <HEAD>
<TITLE>3088.3876</TITLE> </HEAD> <BODY> <H1>Value of $step_data/@Instance is /3088.3876/</H1> <H1>Count of step_data before template invocation is 1 </H1> (Invoking template)
<H1>Value of $step_data/@Instance is /At xsl:value-of on line 26 of file:/ C:/DVLP/docs/tree_error.xsl: Cannot convert value [""] to a node-set
Here's the Xalan output (run with -TT -TS -TG -V): >>>>>>> Xalan Version 1.2D01, XML4J Version Xerces 1.1.2<<<<<<< ========= Parsing file:C:/DVLP/docs/tree_error.xsl ========== Parse of file:C:/DVLP/docs/tree_error.xsl took 820 milliseconds ========= Parsing file:C:/DVLP/docs/tree_error.xml ========== Parse of file:C:/DVLP/docs/tree_error.xml took 280 milliseconds ============================= Transforming... STARTDOCUMENT Line #0, Column #0: xsl:template match='/' Line #5, Column #40: xsl:template match='suspended_step' Line #6, Column #48: xsl:variable, select='.': org.apache.xalan.xpath.dtm.DTMProxy@6b7859 STARTDOCUMENT STARTELEMENT: HTML STARTELEMENT: HEAD Line #9, Column #49: xsl:value-of, select='@Instance': org.apache.xalan.xpath.dtm.DTMProxy@30e280 STARTELEMENT: TITLE CHARACTERS: 3088.3876 ENDELEMENT: TITLE ENDELEMENT: HEAD STARTELEMENT: BODY STARTELEMENT: H1 CHARACTERS: Value of $step_data/@Instance is / Line #12, Column #92: xsl:value-of, select='$step_data/@Instance': org.apache.xalan.xpath.dtm.DTMProxy@4cb029 CHARACTERS: 3088.3876 CHARACTERS: / ENDELEMENT: H1 STARTELEMENT: H1 CHARACTERS: Count of step_data before template invocation is Line #14, Column #56: xsl:value-of, select='count($step_data)': 1 CHARACTERS: 1 ENDELEMENT: H1 CHARACTERS: (Invoking template)
Line #16, Column #64: xsl:apply-templates, select='document('tree_error2.xml')':
org.apache.xalan.xpath.dtm.DTMProxy@7bd9f2
Line #0, Column #0: xsl:template match='/'
Line #24, Column #37: xsl:template match='top_element'
STARTELEMENT: H1
CHARACTERS: Value of $step_data/@Instance is /
XPATH: Can not convert #RTREEFRAG to a NodeList!
Xalan: was not successful.
XSLProcessor: done
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Debug Support in XSL (WAS RE: X, Steve Muench | Thread | Re: Question about result tree frag, Gary L Peskin |
RE: Displaying SVG, Chris Bayes | Date | Re: FW: VAJava XSLT result (perfect, igort |
Month |