"Bart W.Jenkins" wrote:
>
> Gary,
> Ok. I got your sample to work also and now I know why...
> There are 2 things different with your sample...
>
> 1. You use the xsl:variable option in which you place the select as the
> attribute in the xsl:variable element name instead of in the element body.
> That is, you used:
>
> <xsl:variable name="myRTF" select='Ext:getMyXMLStr()'/>
>
> and this works, however...
>
> <xsl:variable name="myRTF">
> <xsl:value-of select='Ext:getMyXMLStr()'/>
> </xsl:variable>
>
> does NOT, and I thought the two forms of declaration were equivalent.
No, they're different. See http://www.w3.org/TR/xslt#variable-values.
The first is a node-set. The second is an RTF, for which you'd need to
use the nodeset extension function if you want to navigate. I think the
first easier because you don't have to use the nodeset extension
function.
>
> 2. Also, you don't use the top level element name in the XPATH call, that
> is, you used...
>
> <xsl:value-of select="$myRTF/ELEM1/ELEM1A"/>
>
> instead of...
>
> <xsl:value-of select="$myRTF/DOCUMENT/ELEM1/ELEM1A"/>
>
> which surprised me! The second form is the correct one if you use the
> document() function to pull in an XML file from a URI, that is, if my
> declaration for getting the xml file had been...
>
> <xsl:variable name="client" select="document('simple2.xml')"/>
>
> and this contained the same data as before, you would need to use
> $myRTF/DOCUMENT/...
>
> Is this difference from the document() function an implementation
> interpretation issue, a peculiarity of the spec, or a mistake?
This is a little confusing. The way I've written getMyXMLStr(), it
returns a node-set consisting of a single node, the DOCUMENT node. If
you want to use your syntax, just change the getMyXMLStr() function to
return the document by changing
NodeSet retval = new NodeSet(elemNode);
to
NodeSet retval = new NodeSet(myDoc);
That way, getMyXMLStr() will return a node-set consisting of a single
node, the document root. Then, your XPath should work fine. The
document() function returns the document root (see
http://www.w3.org/TR/xslt#document) which is why it behaves the way it
does.
If you have more questions, please come back with them. It's important
to understand this stuff.
HTH,
Gary