Diazo xsl: pattern does not apply when inside the secondary rule file

I use Diazo with Plone and have some xsl code that works in the root of rules.xml, but not inside the attached XML file. I would like to keep my rules. Xml is simple and keep the style of the section in each .xml file of each section.

How to add class "subNav" to all li using diazo from section-one.xml?

Doesn't work (but preferably):

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> 

Work (but not desirable):

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> 
+4
source share
2 answers

This has nothing to do with XInclude. Instead, this is a restriction on the handling of embedded XSL inside the <rules if ... /> build.

As Diazo docs note:

Inline XSL directives must be placed directly inside the <rules> root and applied unconditionally.

[Incidentally, the "uncoditionally" in the documents is not entirely true. Using the = "raw" method avoids certain rules.]

Inline XSL is usually added to the generated XSL after the converted theme. Diazo clearly does not know what to do with bare XSL inside the rules if ... />. So he omits this. This is probably good, because nothing else probably makes sense.

By "embedded" XSL, I mean XSL, which is not inside a replacement, after, before, or another rule that attaches to the theme or content elements. Specifically, this is anything using xsl: template.

XSL inside a replacement is not governed by this restriction. So you can 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 need.

+8
source

Configure each rule tag with the corresponding XSL attribute, for example, change section-one.xml to [1]:

 <rules xmlns="http://namespaces.plone.org/diazo" xmlns:css="http://namespaces.plone.org/diazo/css" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <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> 

[1] Not sure if this will work. If this is not the case, you may consider sending a bug report.

0
source

Source: https://habr.com/ru/post/1487162/


All Articles