Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

diazo xsl:template not applying when inside secondary rules file

Tags:

plone

diazo

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>
like image 940
hennaheto Avatar asked Feb 17 '23 04:02

hennaheto


1 Answers

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.

like image 179
SteveM Avatar answered Apr 07 '23 16:04

SteveM