我正在使用带有Plone的Diazo并且有一些xsl代码在rules.xml的根目录中工作,但不在包含的.xml文件中.我想保持我的rules.xml简单,并在每个部分的.xml文件中保留部分特定的样式.
如何使用section-one.xml中的diazo将类"subNav"添加到所有li?
不工作(但需要):
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>
Run Code Online (Sandbox Code Playgroud)
科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>
Run Code Online (Sandbox Code Playgroud)
工作(但不是想要):
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>
Run Code Online (Sandbox Code Playgroud)
科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>
Run Code Online (Sandbox Code Playgroud)
这实际上与XInclude没有任何关系.相反,它是对<rules if ... />构造中的内联XSL处理的限制.
正如Diazo文档所述:
内联XSL指令必须直接放在根<rules>标记内,并且无条件地应用.
[顺便说一句,文档中的"非文明"并不完全正确.使用method ="raw"将避免申请特定规则.]
内联XSL通常在转换后的主题后附加到生成的XSL.Diazo显然不知道如何在<rules if ... />中使用裸XSL.所以,它省略了它.这可能是一件好事,因为其他任何事情都可能没有意义.
通过"内联"XSL,我的意思是XSL不在替换之前,之后或其他附加到主题或内容元素的规则.具体来说,这是使用xsl:template的任何东西.
替换中的XSL不受此限制的约束.因此,您可以将以下内容放在section-one.xml中:
<replace css:content="li">
<xsl:copy>
<xsl:attribute name="class">subNav</xsl:attribute>
<xsl:apply-templates />
</xsl:copy>
</replace>
Run Code Online (Sandbox Code Playgroud)
并得到我认为你想要的东西.