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

Re: xsl:attributes as parameter to a template

Subject: Re: xsl:attributes as parameter to a template
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 3 May 2005 19:53:17 +1000
xsl attributes
On 5/3/05, Jan Tietjens <jan.tietjens@xxxxxxxxxxxxxx> wrote:
> Hello,
> I am not understanding why the following xslt snipped produces an empty
> 'someElement' element (XSLT 1.0):
>
>    <xsl:template match="/">
>        <xsl:call-template name="printSomeAttributes">
>            <xsl:with-param name="attributes">
>                <xsl:attribute name="juhu">Hello World!</xsl:attribute>
>            </xsl:with-param>
>        </xsl:call-template>
>    </xsl:template>
>
>    <xsl:template name="printSomeAttributes">
>        <xsl:param name="attributes"/>
>        <xsl:element name="someElement">
>            <xsl:value-of select="$attributes"/>
>        </xsl:element>
>    </xsl:template>
>


If you run it with Saxon 8.4 the error message that is produced
describes the cause of the problem very well:

   "Error at attribute constructor juhu="{...}" on line 6 of
file:/C:/Program%20Files/Java/jdk1.5.0_01/bin/marrowtr.xsl:
  XTDE0410: Cannot create an attribute node whose parent is a document node
Transformation failed: Run-time errors were reported"


Saxon 6.5.3 produces also a good message:

"Recoverable error
at xsl:attribute on line 6 of file:/(Untitled):
  Cannot write an attribute node when no element start tag is open"

What is happening is that the previous node produced is not an element
(in fact it is a root node), so the attribute (even if created) cannot
be attached to an element node.

The result is either an error (in XSLT 2.0) or a recoverable error (as
in XSLT 1.0) in which case no attribute is present in the output.


Cheers,
Dimitre Novatchev

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.