idazuwaika
idazuwaika

Reputation: 3019

XSLT output to HTML

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

Upvotes: 3

Views: 2228

Answers (5)

VladV
VladV

Reputation: 10389

value="{name}"

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

EDIT: Changed {$name} to {name}

Upvotes: 4

Robert Rossney
Robert Rossney

Reputation: 96920

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}"/>

Upvotes: 5

carillonator
carillonator

Reputation: 4743

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.

Upvotes: 1

Peter Lindqvist
Peter Lindqvist

Reputation: 10210

<xsl:element name="input">
<xsl:attribute name="type">button</xsl:attribute>
<xsl:attribute name="value" select="name">
</xsl:element>

Excellent reference to HTML/XSL

Upvotes: 6

RageZ
RageZ

Reputation: 27323

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

Upvotes: 3

Related Questions