1

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.

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.