Aditya
Aditya

Reputation: 15

Creating HTML tag using XSLT

I have an XML (Here I have shown only a fragment and it has several Control elements,

  <Control Name="submit" ID="">
  <Properties>
    <Property Name="id" Value="btn_Submit" />
    <Property Name="value" Value="Submit" />
  </Properties>
  </Control>

and I want to get html as

<html>
 <head>
  <title>example_htmlPage</title>
 </head>

 <body>
  <input id="btn_Submit" type="submit" value="Submit"/>
 </body>
</html>                    

by using XSLT. I have written an XSLT as

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <html> 
     <head>
        <title>example_htmlPage</title>
     </head>

     <body>
        <xsl:apply-templates/>
     </body>
  </html>
 </xsl:template>
 <xsl:template match="/">
     <xsl:for-each select="//Control[@Name='submit']">
       <input type="submit" value="//Property/@Value/text()"/>
     </xsl:for-each>
  <xsl:apply-templates/>
 </xsl:template>
 </xsl:stylesheet> 

So, my question is how to get the value of an attribute into HTML tag? I couldnt solve it by creating local variable as well as by using

  <input type="submit" value=&lt;xsl:select="(//Property/@Value/text())"/&gt;/>

Please help me.

Upvotes: 1

Views: 1740

Answers (1)

Pino
Pino

Reputation: 9383

Use <xsl:attribute> to add an attribute to a tag:

<input type="submit">
    <xsl:attribute name="value"><xsl:value-of select="./Properties/Property[@Name='value']/@Value" /></xsl:attribute>
</input>

Upvotes: 1

Related Questions