Subject: Re: [xsl] XSL converter for colors values(types) From: Mike Brown <mike@xxxxxxxx> Date: Tue, 9 Oct 2001 17:28:41 -0600 (MDT) |
> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSL converter for colors valu, Kris Kolodziej | Thread | [xsl] Re: Re: Re: Overlapping struc, Dimitre Novatchev |
RE: [xsl] 3 Questions about FOP., Joshua . Kuswadi | Date | [xsl] Re: XSL-List Digest V3 #1158, Avani Goel |
Month |