xsl-list
[Top] [All Lists]

Re: Can a named template return a node list?

2005-06-16 14:45:57



I understand that custom:function is basically a method in a .NET class, 
which does return a pointer/reference to an existing node in the current 
XML document, and I can reference attributes of that node using 
$whatever/@attr instead of $whatever/*/@attr.

both syntaxes work, it just depends what you wnat to select.

$whatever/@attr
selects the attr attribute of each node in the node set bound to
$whatever.

$whatever/*/@attr
selects the attr attribute of each element child of each node in the
node set bound to $whatever.

If you use 
<xsl:variable> with content then it generates a result tree fragment
corresponding to a root node (/) with children whatever nodes are
generated by the content of teh xsl:variable. so then if you go
<xsl:variable name="whatever" select="x:node-set($x)"/>
then clealy you would want to use 
$whatever/*/@attr
as root nodes have no attributes so you need to select elements first.
On the other hand if you go
<xsl:variable name="whatever" select="x:node-set($x)/*"/>
Then $whatever is a node set of element nodes and you can go
$whatever/@attr
to select their attributes.

But in your case you don't want to use x:node-set at all, just select
the nodes you want directly using selct on the xsl:variable.

  I guess this is because  call-template always returns what I would
  call a string, 

No call-template generates nodes not a string, but it doesn't return
anything it places teh nodes into the current output, witherthe main
result document or a result tree fragment being built in a variable.
A result tree frafgment os very different from a string. (It's almost
exactly the same thing as a node set with a single root node, except for
an essentially artificial restriction that you can not query into it.

..

need to know that they sometimes need to add /* to dereference
variables.

The /* is nothing to do with it being a variable it is just usual XPath
syntax distinguishing whether you want to find the attribute of this node
or this node's children.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--