[xsl] Re: taking a literal or a attribute value

Subject: [xsl] Re: taking a literal or a attribute value
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sat, 7 Jun 2003 20:43:08 +0200
"florian" <csshsh@xxxxxxxxxxxxxxx> wrote in message
news:42755243-990D-11D7-93EA-000393C79362@xxxxxxxxxxxxxxxxxx
>
> On Montag, Mai 26, 2003, at 10:55  Uhr, David Carlisle wrote:
>
> >
> >    hi!
> >
> >    i would like to set a xml element attribute to the value of
> >    an currently processed element or a literal.
> >
> >    i could do it for sure like
> >
> >    <xsl:choose>
> >    <xsl:when test="@width"><xsl:value-of select="@width"
> >    /></xsl:when> <xsl:othrwise>100%</xsl:othrwise>
> >    </xsl:choose>
> >
> >    i just wonder if there are any nice xpaths ways to make
> >    this more simple..
> >
> >    thanks alot in advance!
> >
> >    ciao!
> >    florian
> >
> >
> > <foo width="100%">
> >  <xsl:copy-of select="@width"/>
> >
> >
>
> just saw that message =)
>
> i dont really understand that code though. where is the actual
> condition?


The "actual condition" is that if @width is the empty node-set (no "width"
attribute exists, or its value is the empty string), then

  <xsl:copy-of select="@width"/>

will not copy anything and will not override the already specified "width"
attribute of the literal result element "foo".

According to the XSLT 1.0 spec:

"Adding an attribute to an element replaces any existing attribute of that
element with the same expanded-name."
http://www.w3.org/TR/xslt#creating-attributes

Therefore, copying to an element an attribute node with the same name more
than once is not an error and it has its own purpose. In such case the last
overriding copied attribute becomes the attribute of the element that will
be output.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread