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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transform XML to HTML

Status
Not open for further replies.

5C1R6

Programmer
Jul 8, 2006
6
US
using XSLT how do you transform data from XML file to turn it into HTML <div> element, and also set the width and height of the <div> based on the data obtained from XML.

Say, the XML file contains something like:

...
<info>
<divContent>banana</divContent>
<divWidth>100<divWidth>
<divHeight>40<divHeight>
<info>

Thank you

David
 
Thanks.
Actually, I am familiar with that site and have already looked through it before posting this question.

I am able to display the string (banana) inside the <div> by using <xsl:copy-of select=...

I could use the same technique to extract the width and height values from the XML file; the problem is how to assign those values to the div's attributes.
 
Don't know the unit of your data. I make up the unit arbitrarily for illustration.
[tt]
<xsl:template match="info">
<div style="width:{divWidth}[COLOR=green white]%[/color];height:{divHeight}[COLOR=green white]px[/color];">
<xsl:value-of select="divContent" />
</div>
</xsl:template>
[/tt]
 
There goes tsuji using attribute value templates again! [bigsmile] We have an ongoing disagreement about the gratuitous use of attribute value templates.

Let me illustrate obtaining the identical result using the more general purpose xsl:attribute element. Presuming the context is an <info> element:
Code:
<div>
   <xsl:attribute name="style">
      <xsl:value-of select="concat('width:', divWidth,
                                   '&;height:', divHeight,
                                   'px;')"/>
   </xsl:attribute>
</div>

Attribute value templates are limited in the places they may be used, and indeed there are a couple situations where thir use is 'priceless' but this situation allows both solutions.

Tom Morrison
 
Tom, I don't think I disagree with your preferential use on the avt as far as I am concerned. Nevertheless, you might disagree with mine. I am comfortable with your position, absolutely no problem.
- tsuji
 
tsuji, I have no problem with your position either. None at all...[bigsmile]

Now to correct a slight error:
Code:
<div>
   <xsl:attribute name="style">
      <xsl:value-of select="concat('width:', divWidth,
                                   '[b][COLOR=white red]%[/color][/b];height:', divHeight,
                                   'px;')"/>
   </xsl:attribute>
</div>

Tom Morrison
 
Thank you both for the inputs.


David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top