469,963 Members | 1,289 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

Appending to an Attribute

Is there a way to append to an attribute in XSLT.

For example:

<input name="emailaddress" style="width:200px">
<xsl:apply-templates select="//object[id='emailaddress']"/>
</input>

<xsl:template match="//object">
<xsl:attribute name="value"><xsl:value-of select="@dvalue"/></xsl:attribute>
<xsl:attribute name="style"><xsl:value-of select="@error"/></xsl:attribute>
</xsl:template>

In the above example the style attribute value 'width:200px' on the input node is replaced with the value of @error, 'background-color:blue'. What I would like to do is have it append the 'background-color:blue'.

Before you go an say style="width:200px;{//object[@id='emailaddress']/@error}" that is not the solution. I already have that on all the controls. What I am trying to do is come up with a generic template to handle several properties on input boxes.

Cheers
Keith
Nov 12 '05 #1
2 3571
Keith Chadwick wrote:
Is there a way to append to an attribute in XSLT.
Nope. In XSLT one cannot access result tree directly. All you can do
with it - to output nodes there.
<input name="emailaddress" style="width:200px">
<xsl:apply-templates select="//object[id='emailaddress']"/>
</input>

<xsl:template match="//object">
<xsl:attribute name="value"><xsl:value-of
select="@dvalue"/></xsl:attribute>
<xsl:attribute name="style"><xsl:value-of
select="@error"/></xsl:attribute>
</xsl:template>


You should use some other technique here. E.g.
<input name="emailaddress">
<xsl:apply-templates select="//object[id='emailaddress']">
<xsl:with-param name="style" select="'width:200px;'"/>
</xsl:apply-templates>
</input>
<xsl:template match="object[id='emailaddress']">
<xsl:param name="style"/>
<xsl:attribute name="value">
<xsl:value-of select="@dvalue"/>
</xsl:attribute>
<xsl:attribute name="style">
<xsl:value-of select="$style"/>
<xsl:value-of select="@error"/>
</xsl:attribute>
</xsl:template>
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
I will have to think on that one for bit. My WYSIWYG editor in IE creates
the raw html then I have to translate it into a xslt file and a underlying
xml file. So the trade off is who does more of the work, the xslt or the
xml. For instance I could place the base style settings as part of the
object node then it would be a simple concat(@basestyle,@error). That would
mean that the generation of the xslt file would be easier to manage since
there would just be the call to the apply templates on each input control.

Guess I will see as the design progresses!! The dangers of coding with a
loose plan :-)

Cheers
Keith

"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:eg*************@TK2MSFTNGP10.phx.gbl...
Keith Chadwick wrote:
Is there a way to append to an attribute in XSLT.


Nope. In XSLT one cannot access result tree directly. All you can do
with it - to output nodes there.
<input name="emailaddress" style="width:200px">
<xsl:apply-templates select="//object[id='emailaddress']"/>
</input>

<xsl:template match="//object">
<xsl:attribute name="value"><xsl:value-of
select="@dvalue"/></xsl:attribute>
<xsl:attribute name="style"><xsl:value-of
select="@error"/></xsl:attribute>
</xsl:template>


You should use some other technique here. E.g.
<input name="emailaddress">
<xsl:apply-templates select="//object[id='emailaddress']">
<xsl:with-param name="style" select="'width:200px;'"/>
</xsl:apply-templates>
</input>
<xsl:template match="object[id='emailaddress']">
<xsl:param name="style"/>
<xsl:attribute name="value">
<xsl:value-of select="@dvalue"/>
</xsl:attribute>
<xsl:attribute name="style">
<xsl:value-of select="$style"/>
<xsl:value-of select="@error"/>
</xsl:attribute>
</xsl:template>
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by bucket79 | last post: by
reply views Thread by Red Ogden | last post: by
4 posts views Thread by John A Grandy | last post: by
3 posts views Thread by hharry | last post: by
7 posts views Thread by Lonnie Princehouse | last post: by
1 post views Thread by irixdude | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.