Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert xml attribute to html tag

Status
Not open for further replies.

graffitici

Programmer
Jul 12, 2005
3
TR
Hi,

I am trying to generate an HTML file from XML using XSLT (a very mundane sentence!). However I can't get to insert the value of an xml tag, as the "name" attribute of an input element. My html file looks like this:

<?xml version="1.0" encoding="ISO-8859-9" ?>
<?xml-stylesheet type="text/xsl" href="rpg.xsl"?>
<rpg>
<soru id="soru1">
<text> soru txt </text>
</soru>
</rpg>

And I want to do this:

...
<input type="radio" name="soru1" />
...

The first thing I tried was to do

<input type="radio" name="<xsl:value-of match="../@id" /> />

Which obviously didn't work, since the xml wasn't well formed. I then tried replacing the less-than characters with the corresponding entity &lt;, but that just prints it on the page instead of generating a radio button.

What do you think I should do?

thanks...
bB
 
Use <xsl:attribute>.

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

Tom Morrison
 
Whilst this way works perfectly fine, there is a shorthand method (curly brackets):
Code:
<input type="radio" name="{@id}" />

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
Yeah I also just found out about the brackets. They seem handy, but not very elegant or rigorous. Anyway, if it works, it's good enough for me.

Thanks to both for your answers,
bB
 
Why are they not elegant/rigorous?

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
Because it's not xml syntax. It's an "exception," as in "all the information is between tags *except* for the ${..} syntax in attributes."

That is only my opinion anyway.

bB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top