I am using Diazo with Plone and have some xsl code that is working in the root of rules.xml but not inside an included .xml file. I would like to keep my rules.xml simple and keep the section specific styling inside each section's .xml file.
How can I add the class "subNav" to all li's using diazo from section-one.xml?
Not working (but desired):
rules.xml
<?xml version="1.0" encoding="UTF-8"?>
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude">
<rules if-path="section-one/">
<xi:include href="section-one.xml" />
<theme href="templates/section-one.html" />
</rules>
<rules if-not-path="section-two/">
<xi:include href="section-two.xml" />
<theme href="templates/section-two.html" />
</rules>
</rules>
section-one.xml
<?xml version="1.0" encoding="UTF-8"?>
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude">
<replace css:content="#content" css:theme="#content"/>
<xsl:template match="//li">
<xsl:copy>
<xsl:attribute name="class">subNav</xsl:attribute>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</rules>
Working (but not desired):
rules.xml
<?xml version="1.0" encoding="UTF-8"?>
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude">
<rules if-path="section-one/">
<xi:include href="section-one.xml" />
<theme href="templates/section-one.html" />
</rules>
<rules if-not-path="section-two/">
<xi:include href="section-two.xml" />
<theme href="templates/section-two.html" />
</rules>
<xsl:template match="//body[contains(@class, 'section-one')]//li">
<xsl:copy>
<xsl:attribute name="class">subNav</xsl:attribute>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</rules>
section-one.xml
<?xml version="1.0" encoding="UTF-8"?>
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude">
<replace css:content="#content" css:theme="#content"/>
</rules>
This doesn't actually have anything to do with the XInclude. Instead, it's a limitation on the processing of inline XSL inside a <rules if... /> construct.
As the Diazo docs note:
Inline XSL directives must be placed directly inside the root <rules> tag and are applied unconditionally.
[By the way, the "uncoditionally" in the docs is not quite true. Using method="raw" will avoid application for particular rules.]
Inline XSL is normally appended to the generated XSL after the transformed theme. Diazo clearly does not know what to do with bare XSL inside a <rules if... />. So, it omits it. This is probably a good thing, since anything else probably wouldn't make sense.
By "inline" XSL, I mean XSL that is not inside a replace, after, before or other rule that attaches to elements of the theme or content. Concretely, this is anything using xsl:template.
XSL inside a replace is not governed by this limitation. So, you could put the following in your section-one.xml:
<replace css:content="li">
<xsl:copy>
<xsl:attribute name="class">subNav</xsl:attribute>
<xsl:apply-templates />
</xsl:copy>
</replace>
and get what I think you're after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With