Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespace breaks xsl:attribute when Modifying theme on-the-fly #52

Open
davilima6 opened this issue Nov 12, 2015 · 5 comments
Open

Whitespace breaks xsl:attribute when Modifying theme on-the-fly #52

davilima6 opened this issue Nov 12, 2015 · 5 comments

Comments

@davilima6
Copy link
Member

This works:

  <replace css:theme-children="#portal-logo">
    <img alt="Site Logo" class="img-responsive"><xsl:attribute name="src"><xsl:value-of select="$site_logo" /></xsl:attribute></img>
  </replace>

This does not:

  <replace css:theme-children="#portal-logo">
    <img alt="Site Logo" class="img-responsive">
      <xsl:attribute name="src"><xsl:value-of select="$site_logo" /></xsl:attribute>
    </img>
  </replace>

Even this won't work (one single whitespace before xsl:attribute):

  <replace css:theme-children="#portal-logo">
    <img alt="Site Logo" class="img-responsive"> <xsl:attribute name="src"><xsl:value-of select="$site_logo" /></xsl:attribute></img>
  </replace>

Here's the error msg:

_runtime error, element 'attribute' [123:0]
xsl:attribute: Cannot add attributes to an element if children have been already added to the element. [0:0]
_

Using Plone 4.3.

/cc @ebrehault @davisagli @lrowe

@lrowe
Copy link
Member

lrowe commented Nov 12, 2015

My initial reaction is to just close this as whitespace is significant in html and diazo puposefully preserves it - the whitespace following the open tag is therefore treated as a text node and any xsl:attributes may not follow a text node.

We do currently special case blank text node children of xsl elements: https://github.com/plone/diazo/blob/1.2.2/lib/diazo/emit-stylesheet.xsl#L261-L271 so perhaps an argument could be made for special casing blank text nodes that immediately lead or follow an xsl element. That would change behaviour of code like this though:

  <replace css:theme="#welcome">
    <p>Hello <include css:content="#username"/></p>
  </replace>

@davilima6
Copy link
Member Author

Thanks for the quick response, Lawrence. Let me see if I understand. Are you saying that in order to make room for my proposed usecase the result of your example rule would be <p>Hellousername</p>, without whitespace? I mean, can't we have the best of both worlds?

If that's an XSL limitation then we should just document it better, since this syntax seems to differ from HTML nodes expected behavior.

@lrowe
Copy link
Member

lrowe commented Nov 13, 2015

I got my example case slightly wrong as it would only affect whitespace only text nodes:

  <replace css:theme-content="#welcome">
    <b>Hello</b> <xsl:value-of select="$username"/>
  </replace>

Currently it produces <b>Hello</b> username whereas to support your usecase we'd need to special case blank text nodes before and after an xsl element the same as a blank child node of an xsl element, so you'd get ``Hellousername` without the space.

@frapell
Copy link
Member

frapell commented Nov 19, 2015

Does it make sense to add such a special case? or should we just improve documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants