Subject: RE: what are node set fragments and why are they ruining my life? From: Kay Michael <Michael.Kay@xxxxxxx> Date: Tue, 14 Dec 1999 10:07:59 -0000 |
Firstly, they aren't called node set fragments, they are called result tree fragments. Not a pretty name, and the abbreviation RTF is unfortunate, but we have to live with it. When the body of an <xsl:variable> element is evaluated (or "instantiated" to use the correct jargon), the result is written to an RTF. There are only three things you can do with an RTF: you can use xsl:copy-of to copy it to the result tree (or to another RTF), you can convert it implicitly or explicitly to a string, and you can pass it to a function. There aren't any standard functions that process RTFs, so in practice this means an extension function. SAXON and xt both provide extension functions to convert an RTF to a node-set. This conversion can't be done implicitly. The reason your xsl:for-each fails is that the expression in the select attribute must yield a node-set. Nothing else will do, in particular, it cannot be an RTF. With your <xsl:for-each> commented out, the SAXON message output is what I would expect; I can't comment on the xt output. Step back: what is the problem you are trying to solve? Mike Kay > -----Original Message----- > From: Mark D. Anderson [mailto:mda@xxxxxxxxxxxxxx] > Sent: 14 December 1999 04:14 > To: xsl-list@xxxxxxxxxxxxxxxx > Subject: what are node set fragments and why are they ruining my life? > > > see the minimal xsl and xml file below. > > first off, nothing i've read in the spec or the various xsl tutorials > make any sense in defining what a node set fragment is. > they talk about things like "not being well-formed", but (a) i'm not > clear how one is able to produce something that isn't well-formed, > and (b) that doesn't match experience as this example shows. > > here i've shown where the mere act of passing a node set (fragment) > through a call-template is enough to defile it. > > here are the various outputs. > > 1. comment out first for-each, use xt > output is: > member 1 > > note that there is a result, but no xsl:message instructions are run > > 2. comment out first for-each, use saxon > output is: > member local-name=member, id=1 > member local-name=member, id=2 > > note that there is no result, but the xsl:message instructions are run > > 3. leave in first for-each, use xt > output is: > cannot convert to node-set > > 4. leave in first for-each, use saxon > member local-name=member, id=1 > member local-name=member, id=2 > Error during source document processing > At xsl:for-each on line 32 of > file:/d:/mda/projects/xmlhacks/xmlidl/test1.xsl: Cannot > convert value [** RESULT TREE FRAGMENT **] to > a node-set > > Thanks to anyone who can elucide this matter. > > -mda > > test1.xml > > <root> > <member id="1">member 1</member> > <member id="2">member 2</member> > </root> > > > test1.xsl > > <?xml version="1.0" ?> > > <xsl:stylesheet > version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:date="http://www.jclark.com/xt/java/java.util.Date" > xmlns:xt="http://www.jclark.com/xt" > xmlns:sxf="/com.icl.saxon.functions.Extensions" > extension-element-prefixes="date xt sxf" > exclude-result-prefixes="date sxf xt" > > > <xsl:output > method="html" > indent="yes" > doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" > /> > <xsl:strip-space elements="*"/> > > <xsl:template match="root"> > <xsl:variable name="members"> > <xsl:call-template name="get_members"/> > </xsl:variable> > <!-- why can't i use a variable? something about result > tree fragments... --> > > <!-- comment this for-each out to avoid the runtime error > <xsl:for-each select="$members"> > <xsl:message>member local-name=<xsl:value-of > select="local-name(.)"/>, id=<xsl:value-of > select="@id"/></xsl:message> > </xsl:for-each> > --> > <xsl:value-of select="$members"/> > </xsl:template> > > <xsl:template name="get_members"> > <xsl:variable name="result" select="*"/> > <xsl:for-each select="$result"> > <xsl:message>member local-name=<xsl:value-of > select="local-name(.)"/>, id=<xsl:value-of > select="@id"/></xsl:message> > </xsl:for-each> > <!-- same thing as: <xsl:value-of select="$result"/> --> > <xsl:value-of select="*"/> > </xsl:template> > > </xsl:stylesheet> > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: what are node set fragments and, James Clark | Thread | RE: what are node set fragments and, Mike Brown |
RE: message and recursion, Kay Michael | Date | RE: dynamically reading tag-names i, Kay Michael |
Month |