Diazo, HTML5 and XSL fun

written on 2011-11-05

So everything you needed to do for xdv to get it to go HTML5 is now no longer necessary. I thought I'd have to use a registry.xml to be able to have a HTML5 doctype, which wouldn't help much with the zip deployment of themes. But yesterday I saw it set in a manifest.cfg on the ploneconf (2011).

An example HTML5 manifest.cfg file:

title = My Theme
description = Description of your theme
rules = /++theme++my.theme/directory/rules.xml
prefix = /++theme++my.theme/directory
doctype = <!DOCTYPE html>

Another nifty little trick I've seen yesterday was the use of xsl:apply-templates and css:select. For instance if you want to do something silly with your breadcrumb.

<xsl:if css:test="#breadcrumb-1">
  <append css:theme="#breadcrumb">
    <xsl:for-each css:select="#portal-breadcrumbs > span:not(#breadcrumbs-you-are-here) > *" method="raw">
        <xsl:when css:test=".breadcrumbSeparator">
          <span class="separator"> > </span>
          <xsl:apply-templates css:select="a, span"/>

The above example basicly does this:

  1. xsl:if

    : This tests if the "breadcrumb-1" id is available (when you have

    more than just home)
  2. append

    : Select the div with the breadcrumb id

  3. xsl:for-each

    : Loops through all the children of spans, directly under

    portal-breadcrumbs, that do not have the
    "breadcrumbs-you-are-here" id.
  4. xsl:choose

    : For when you have multiple scenarios. In this case sort of if

    else, but you could have lots of different cases.
  5. xsl:when

    : First scenario, in this case selecting the breadcrumb separator

    and changing it.
  6. span

    : Yes, you can add html structure like this.

  7. xsl:otherwise

    : If none of the above scenario's match, then do this.

  8. xsl:apply-templates

    : Put the content you select into the theme side. In case of a

    for-each the selection is relative to the for each select.

The xsl:apply-templates bit I used to do by useing xsl:copy-of, which put the content there, but takes it out of the xdv loop. The xsl:apply-templates way leaves it in.

Other fun tricks

You can use an href to draw in content from outside of the content page. In plone you can use it for browser view for instance. The following example gets in the html in the @@login-form browser view: <append css:theme="" css:content="form" href=%22@@login_form" />

To select comments, for instance one that has the word 'base' somewhere in there use //comment()[contains(., 'base')]. The following example moves the base tag from the content to the comments in the theme that contain the word base: <replace theme="//comment()[contains(., 'base')]" css:content="base"/>