[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Can a named template return a node list?

Subject: Re: Can a named template return a node list?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 17 Jun 2005 06:18:43 +1000
xslt template return
>   <xsl:variable name="somenode" select="msxsl:node-set( $somedata )" />
>   <xsl:value-of select="$somenode/@attr" />

You are trying to get the value of an attribute of the document node
of a temporary tree.

A document nodes (root nodes in XSLT 1.0 terminology) doesn't have
attributes as it is not an element node.

Probably you meant:

          <xsl:value-of select="$somenode/*/@attr" />


Cheers,
Dimitre Novatchev

On 6/17/05, John <john-xsl-list@xxxxxxxx> wrote:
> Thanks.  I want to use a named template to avoid putting certain XPath
> statements in multiple locations.  Maybe there is a better way.
>
> Since I don't think there is a pure XSL solution I have been trying with
> node-set, but that's not working for me either.  This seems to give no
> output; I am pretty sure the solution is something obvious but I don't
> see it.
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:msxsl="urn:schemas-microsoft-com:xslt">
>
> <xsl:template match="*">
>   <xsl:variable name="somedata">
>     <xsl:call-template name="sometemplate" />
>   </xsl:variable>
>   <xsl:variable name="somenode" select="msxsl:node-set( $somedata )" />
>   <xsl:value-of select="$somenode/@attr" />
> </xsl:template>
>
> <xsl:template name="sometemplate">
>   <xsl:copy-of select="/root/node1" />
> </xsl:template>
>
> </xsl:stylesheet>
>
> And the sample data again:
>
> <root>
>   <node1 attr="node1attrval">
>     <node1a>node1atext</node1a>
>   </node1>
>   <node2 attr="node1attrval">
>     <node2a>node2atext</node2a>
>   </node2>
> </root>
>
> David Carlisle wrote:
> >  <xsl:variable name="somenode">
> >      ....
> >
> > xsl:variable with content and no select attribute always (in xslt1)
> > generates a result tree fragment not a node set. Therefor you can not
> > query into the variable using XPath (or anything else) You can only copy
> > it to the result, using copy-of or use it as a string.
> >
> >
> >
> >>and I am hoping  to stay away from XSL extensions if possible.
> >
> >
> > It's hard to avoid xx:node-set() (which is designed exactly to get round
> > this problem) Most systems have a node-set() extension function (with
> > mozilla's transformiix engine being the main exception)
> >
> > Of course if your templates are not actually creating any new nodes (as
> > in your example) then you have an easy solution: just use xsl:variable
> > with select as in
> >
> > <xsl:template match="*">
> >    <xsl:variable name="somenode"select="/root/node1" />
> >    <xsl:value-of select="$somenode/@attr" />
> > </xsl:template>
> >
> > David

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.