plone / diazo

Diazo applies a static HTML theme to a dynamic website
http://diazo.org
Other
41 stars 26 forks source link

Transformation fails on themes with HTML 5 data-* attributes #21

Closed seocam closed 10 years ago

seocam commented 10 years ago

I'm trying to use a theme that has the following tag:

<div id="browserid-info" style="display: none;" data-user-email="fakeuser@fakeaddress.com" data-request-args="{}">
File "xslt.pxi", line 596, in lxml.etree.XSLT.__call__ (src/lxml/lxml.etree.c:141082)
XSLTApplyError: Internal error: Failed to evaluate the AVT of attribute 'data-request-args'.

I've tried to use html5lib and subclass etree.HTMLParser and htm5parser.HTMLParser creating an HTML parser that supports HTML5 and also can be passed as argument to etree.parse. The parser actually worked but it didn't fix my bug since the problem is happening during transformation and not parsing. Here is where the problem happens:

output_html = transform(content_doc, **params)

Are there any params that could help me here?

Unfortunately stripping data-* attributes is not an option for me.

seocam commented 10 years ago

Just found out that the problem isn't actually with the data-* attributes but with the JSON stored inside it. The XSL template tries to interpret the empty {} as an XPath expression and obviously that won't work.

Doing a quick search I found that attributes with curly brackets can be safely set using <xsl:attribute> [1].

Is it worth to add some kind of treatment for that on compile_theme?

[1] https://mikewest.org/2007/06/escaping-curly-braces-in-xslt-attributes

seocam commented 10 years ago

Closing in favor for pull request #22