tags:

views:

115

answers:

5

Hi,

In my XSLT file, I have the following:

<input type="button" value= <xsl:value-of select="name">>

It's an error as it violates XML rule.

What I actually want is having a value from an XML file assigned to 'value' parameter in the HTML output. How do I do this? Thanks

+2  A: 

you shoud do something like this

<xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="url" /></xsl:attribute> <xsl:attribute name="target">_blank</xsl:attribute></xsl:element>

more reference on xsl:attribute

RageZ
oh.. so easythanks.
idazuwaika
@idazuwaika: you are welcomed!
RageZ
+4  A: 
value="{name}"

See http://www.w3.org/TR/xslt#attribute-value-templates

EDIT: Changed {$name} to {name}

VladV
@VladV that a variable setup ... he is using `value-of`
RageZ
Yep, look like I misread the question.
VladV
@VladV - Just update the answer to value="{name}"
Mads Hansen
+1 <input type="button" value="{name}">
Eric Bréchemier
I am not sure it works guys me I always use the `xsl:attribute`
RageZ
+6  A: 
<xsl:element name="input">
<xsl:attribute name="type">button</xsl:attribute>
<xsl:attribute name="value" select="name">
</xsl:element>

Excellent reference to HTML/XSL

Peter Lindqvist
A: 

Yes, using <xsl:element> is the way to go here, but you got your parsing error because you didn't close out the <xsl:value-of select="name" /> element. Notice the / at the end; all XML elements need closure, unlike HTML.

carillonator
+4  A: 

It's not at all necessary to use xsl:element; I don't know why so many people are suggesting it. This will work:

<input type="button">
   <xsl:attribute name="value">
      <xsl:value-of name="name"/>
   </xsl:attribute>
</input>

...but even better is using an attribute value template:

<input type="button" value="{name}"/>
Robert Rossney