Subject: [xsl] XSLT CSS Style -> CSS Element with attribute value From: "Alex Neblett" <alexneblett01@xxxxxxxxx> Date: Sat, 7 May 2005 07:59:09 -0500 |
Hello! I am attempting to do something which has probably been done before and which others will want to do as well. When processing xhtml with inline css, it is not so easy to process the individual css attributes and values as they are just a string in the @style attribute. So, I came up with the idea of creating an element containing the attributes and values to make it easy to process the css. In addition, it would accommodate upper/lower case and spacing variances. Ultimately, this would become a template which would be called with a parameter containing the ./@style and the template would return the <css attribute="value"... /> nodeset which could then be easily processed by xslt. I have used exslt to make the process easier and have started with a simple sniplet for debuging purposes. I have included enough debugging information to show the problem to someone with greater knowledge than mine. However, I am missing something simple in my xslt as it does not work, but I am unable to ascertain why. Thank you in advance for your kind assistance. Best Regards, Alex XSLT Sniplet... --------------- <xsl:variable name="cssvar"> <xsl:element name="css"> <xsl:choose> <xsl:when test="contains(string(./@style),';')"> <xsl:for-each select="str:tokenize(string(./@style),';')"> <xsl:attribute name="normalize-space(translate(substring-before(.,':'),'ABCDEFGHIJKLMNOPQRS TUVWXYZ','abcdefghijklmnopqrstuvwxyz'))" ><xsl:value-of select="normalize-space(substring-after(.,':'))"/></xsl:attribute> </xsl:for-each> </xsl:when> <xsl:otherwise> <xsl:attribute name="normalize-space(translate(substring-before(string(./@style),':'),'ABCD EFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'))" ><xsl:value-of select="normalize-space(substring-after(string(./@style),':'))"/></xsl:attri bute> </xsl:otherwise> </xsl:choose> </xsl:element> </xsl:variable> <xsl:variable name="cssvara"> <xsl:element name="css"> <xsl:attribute name="display">inline</xsl:attribute> <xsl:attribute name="font-size">10pt</xsl:attribute> <xsl:attribute name="font-family">Times New Roman, serif</xsl:attribute> </xsl:element> </xsl:variable> <xsl:comment> [[[<xsl:value-of select="string(./@style)"/>]]] [[<xsl:value-of select="string($cssvar)"/>]] [<xsl:value-of select="exslt:node-set($cssvar)/css/@display"/>] [<xsl:value-of select="exslt:node-set($cssvar)/css/@font-size"/>] [<xsl:value-of select="exslt:node-set($cssvar)/css/@font-family"/>] [[[[<xsl:value-of select="string($cssvara)"/>]]]] [<xsl:value-of select="exslt:node-set($cssvara)/css/@display"/>] [<xsl:value-of select="exslt:node-set($cssvara)/css/@font-size"/>] [<xsl:value-of select="exslt:node-set($cssvara)/css/@font-family"/>] [[]] [ <xsl:choose> <xsl:when test="contains(string(./@style),';')"> <xsl:for-each select="str:tokenize(string(./@style),';')"> <xsl:value-of select="normalize-space(translate(substring-before(.,':'),'ABCDEFGHIJKLMNOPQ RSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'))" /><xsl:value-of select="normalize-space(substring-after(.,':'))"/> </xsl:for-each> </xsl:when> <xsl:otherwise> <xsl:value-of select="normalize-space(translate(substring-before(string(./@style),':'),'AB CDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'))" /><xsl:value-of select="normalize-space(substring-after(string(./@style),':'))"/> </xsl:otherwise> </xsl:choose> ] </xsl:comment> RESULT: ------------- <!-- [[[display: inline; FONT-SIZE: 10pt; FONT-FAMILY: Times New Roman, serif]]] [[]] [] [] [] [[[[]]]] [inline] [10pt] [Times New Roman, serif] [[]] [ displayinlinefont-size10ptfont-familyTimes New Roman, serif ] -->
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Building Dynamic Urls, George Cristian Bina | Thread | [xsl] Can't get predicates working., Marco Mastrocinque |
Re: [xsl] minor grouping issue, Bruce D'Arcus | Date | RE: [xsl] minor grouping issue, Michael Kay |
Month |