Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL: putting a XSL value inside an html attribute?

Reply
Thread Tools

XSL: putting a XSL value inside an html attribute?

 
 
Kourosh
Guest
Posts: n/a
 
      05-17-2006
I can't figure out how to do this because the tags have to be properly
nested... and I dont have much XSL experience. Say I'm generating an
HTML tag in my XSL file, and for one of it's attributes, I want to put
the value of an XSL tag... for example:

XSL file...
......
<xsl:template match="/"
<div class = "{value of XSL tag 'entry' goes here}" > hello
world</div>
</xsl:template>

how would I do this?
thanks in advance

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      05-17-2006
I presume you actually meant
<div class = "{value of XSL tag 'entry' goes here}"> hello world</div>

The question is: What do you mean by "value of XSL tag 'entry'"?
Depending on what value you're actually trying to obtain, you may be
able to use an Attribute Value Template as here, or you may need to use
<xsl:attribute> to create this attribute.
 
Reply With Quote
 
 
 
 
Kourosh
Guest
Posts: n/a
 
      05-17-2006
well yea my example up there wasnt accurate. My xml file is like
this:

<entry>
<type>128</type>
</entry>
<entry>....</entry
<entry>....

so in the XSL file, I have a template that looks at each 'entry' tag
and creates an html DIV tag for it. As the div tag is created, I want
the 'type' tag (inside each entry) to be used as its class name.
is that more clear??
so for the first entry above, it would create something like

<div class="128">some text here</div>

 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      05-17-2006
Sounds like what you want is something like

<xsl:template match="entry">
<div class="{type}">some text here</div>
</xsl:template>

or

<xsl:template match="entry">
<div>
<xsl:attribute name="class">
<xsl:value-of select="type"/>
</xsl:attribute>
<xsl:text>some text here</xsl:text>
</div>
</xsl:template>
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      05-17-2006
BTW, the xsl:text in the second version was mostly for readability; I
could have written it as

<xsl:template match="entry">
<div>
<xsl:attribute name="class">
<xsl:value-of select="type"/>
</xsl:attribute>some text here</div>
</xsl:template>

but that would tend to obscure the intent.
 
Reply With Quote
 
Kourosh
Guest
Posts: n/a
 
      05-17-2006
oh wow I didnt know it'd be that simple thanks! I'll try it out.

So the second example that you have... does that actually put the
attribute inside the div tag?

 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      05-17-2006
Kourosh wrote:
> I can't figure out how to do this because the tags have to be properly
> nested... and I dont have much XSL experience. Say I'm generating an
> HTML tag in my XSL file, and for one of it's attributes, I want to put
> the value of an XSL tag... for example:


See http://xml.silmaril.ie/authors/makeup/

> XSL file...
> .....
> <xsl:template match="/"
> <div class = "{value of XSL tag 'entry' goes here}" > hello
> world</div>
> </xsl:template>
>
> how would I do this?


<div class="{entry}">

But that presupposes that "entry" is a child element of the context
node. If "entry" is somewhere else in the document, you have to give
the XPath to it.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
How to put XSLT element <xsl:value-of> inside an HTML tag? Matt XML 1 10-12-2004 09:02 AM
How to put XSLT element <xsl:value-of> inside an HTML tag? Matt Java 1 10-12-2004 12:36 AM
Difference between putting code in constructor and putting code in static{} Saurabh Java 6 05-30-2004 02:44 PM
Putting a server side control inside an html element attribute John Lau ASP .Net 4 05-05-2004 12:42 AM



Advertisments