Re: [xsl] trying to set a parameter equal to an elements attribute

Subject: Re: [xsl] trying to set a parameter equal to an elements attribute
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 21 Aug 2002 15:22:44 -0600 (MDT)
Noel Golding wrote:
> > <!-- XML FILE -->
> > <root>
> >     <header volume="8"/>
> >
> >     <article>
> >         <para>
> >             Some text here
> >        </para>
> >     </article>
> > </root>
> >
> > <!-- XSLT FILE -->
> > <xsl:stylesheet version="1.0" xmlns:xsl="">
> >     <xsl:template match="root">
> >         <xsl:param name="vol"><xsl:value-of select="header[@volume]"/>
> >     </xsl:template>
> > </xsl:stylesheet>

1. you need to put the XSLT namespace name in the xmlns:xsl

2. xsl:variable and xsl:param create a new object and give it a name.
   xsl:value-of creates a text node, unless there is no text to create.

Assuming you meant to put </xsl:param> after the value-of, what you did was
try to set $vol to whatever value for it was passed into the template. None
was (unless there's more to your stylesheet), so $vol was instead set to be a
new object of type "result tree fragment" (which is a non-traversable
node-set). This object consisted of a root node with one child: the text node
that was created by xsl:value-of.  You created this 'vol' object but you never
made reference to $vol, so you got no output.

I assume you just wanted

<xsl:template match="root">
  <xsl:value-of select="header[@volume]"/>


<xsl:template match="root">
  <xsl:variable name="vol" select="header[@volume]"/>
  <xsl:value-of select="$vol"/>

or, if you're passing in $vol from outside the stylesheet, but defaulting
it to header[@volume] if it's not passed in, you need a top-level param:

<xsl:param name="vol" select="/root/header[@volume]"/>

<xsl:template match="root">
  <xsl:value-of select="$vol"/>

   - Mike
  mike j. brown                   |  xml/xslt:
  denver/boulder, colorado, usa   |  resume:

 XSL-List info and archive:

Current Thread