color value from xml to backgroundcolor div in xhtml
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 26
- Joined: Tue Dec 22, 2009 2:40 pm
color value from xml to backgroundcolor div in xhtml
Post by metalhammer »
Hi,
I have RGB value's in my XML file, they look like this:
I want a square in my html file with those RGB value's as color.
I've tried this:
But I can't put an xslt element in an attribute of a div element.
Is there an other way to do this?
I have RGB value's in my XML file, they look like this:
Code: Select all
<egInk:r>.3218039274</egInk:r>
<egInk:g>.4258823395</egInk:g>
<egInk:b>.4894117713</egInk:b>
I've tried this:
Code: Select all
<div class="kleurvak" style="background-color:rgb(<xsl:value-of select="round(egInk:r*256)"/>,<xsl:value-of select="round(egInk:g*256)"/>,<xsl:value-of select="round(egInk:b*256)"/>);">
</div>
Is there an other way to do this?
-
- Site Admin
- Posts: 275
- Joined: Thu Dec 24, 2009 11:21 am
Re: color value from xml to backgroundcolor div in xhtml
Hello,
There are two ways to obtain what you want.
Instead of directly declaring the "div" element and its attributes in the stylesheet, you can generate them using the xsl:element and xsl:attribute elements (http://www.w3.org/TR/xslt#section-Creat ... sl:element). Here is an example of how you can do this:
Another way to obtain the result is by using the attribute value templates feature of XSLT (http://www.w3.org/TR/xslt#attribute-value-templates). This means you can use an xpath expression inside an attribute value by surrounding it with curly braces ({}). In your case it will look something like this:
Let us know if you have further questions regarding this issue.
Regards,
Alin
There are two ways to obtain what you want.
Instead of directly declaring the "div" element and its attributes in the stylesheet, you can generate them using the xsl:element and xsl:attribute elements (http://www.w3.org/TR/xslt#section-Creat ... sl:element). Here is an example of how you can do this:
Code: Select all
<xsl:element name="div">
<xsl:attribute name="class">kleurvak</xsl:attribute>
<xsl:attribute name="style">
<xsl:text>background-color:rgb(</xsl:text>
<xsl:value-of select="round(egInk:r*256)"/>
<xsl:text> , </xsl:text>
<xsl:value-of select="round(egInk:g*256)"/>
<xsl:text> , </xsl:text>
<xsl:value-of select="round(egInk:b*256)"/>
<xsl:text>)</xsl:text>
</xsl:attribute>
</xsl:element>
Code: Select all
<div class="kleurvak" style="background- color:rgb({round(egInk:r*256)},{round(egInk:g*256)},{round(egInk:b*256)})">
</div>
Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 26
- Joined: Tue Dec 22, 2009 2:40 pm
Re: color value from xml to backgroundcolor div in xhtml
Post by metalhammer »
Thanks a lot! Works perfectly!
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service