|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSL converter for colors values(types)
> Is there a converter/XSL stylesheet that already exists for transferring
> hexadecimal color values, i.e., 0xFFFFFF,
> to RGB values, i.e., (255, 255, 255) - ?
>
> Or anything that can help me converting one from the other without
> requiring me to reinvent the wheel?
Oh, just reinvent the wheel :)
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<!-- the color hexcode to split into decimal r,g,b components -->
<xsl:variable name="hexval" select="'EAEAD9'"/>
<result>
<hex>
<xsl:value-of select="$hexval"/>
</hex>
<dec>
<R>
<xsl:call-template name="hexpairs-to-dec">
<xsl:with-param name="pair" select="1"/>
<xsl:with-param name="hexval" select="$hexval"/>
</xsl:call-template>
</R>
<G>
<xsl:call-template name="hexpairs-to-dec">
<xsl:with-param name="pair" select="2"/>
<xsl:with-param name="hexval" select="$hexval"/>
</xsl:call-template>
</G>
<B>
<xsl:call-template name="hexpairs-to-dec">
<xsl:with-param name="pair" select="3"/>
<xsl:with-param name="hexval" select="$hexval"/>
</xsl:call-template>
</B>
</dec>
</result>
</xsl:template>
<xsl:template name="hexpairs-to-dec">
<xsl:param name="pair" select="1"/>
<xsl:param name="hexval"/>
<xsl:variable name="hexpair" select="substring($hexval,$pair * 2 - 1,2)"/>
<xsl:if test="$hexpair">
<xsl:variable name="hex" select="'012345679ABCDEF'"/>
<xsl:value-of select="(string-length(substring-before($hex,substring($hexpair,1,1)))+1)*16 + string-length(substring-before($hex,substring($hexpair,2,1)))+1"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








