xsl-list
[Top] [All Lists]

Re: xsl:attributes as parameter to a template

2005-05-03 02:53:17
On 5/3/05, Jan Tietjens <jan(_dot_)tietjens(_at_)gentleware(_dot_)com> 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

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>