[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT CSS Style -> CSS Element with attribute value

Subject: XSLT CSS Style -> CSS Element with attribute value
From: "Alex Neblett" <alexneblett01@xxxxxxxxx>
Date: Sat, 7 May 2005 07:59:09 -0500
xslt css
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.