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.
Configure each rule tag with the appropriate XSL attribute e.g., 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 this will work. If it doesn't, you might consider filing a bug report
Related
Adding custom css to specific page to magento by external css file in layout update xml, i only want to style the HTML code elements on my page content area.
Im creating drop down menu on the page content area, and inline css dose not support ul, li, hover etc function, the only way to style it will be adding custom css to it. And i must connect externally.
here is my code:
<reference name="head">
<block type="core/text" name="drop_down_menu_lock">
<action method="setText">
<text><![CDATA[<link rel="stylesheet" type="text/css" href="http://link/public_html/wordpress/drop_down_menu_lock.css">]]>
</text>
</action>
</block>
</reference>
Hello you can add below code into specific page xml like this
<catalog_product_view translate="label">
<reference name="head">
<block type="core/text" name="drop_down_menu_lock">
<action method="setText">
<text><![CDATA[<link rel="stylesheet" type="text/css" href="http://link/public_html/wordpress/drop_down_menu_lock.css">]]>
</text>
</action>
</block>
</reference>
</catalog_product_view>
Whilst transforming XHTML to XHTML with XSL I have a problem with namespaces. Consider as an example input:
<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Test</title></head>
<body>
<p>Remove this</p>
</body>
</html>
Then the following transformation does not work (e.g. does not remove the <p />):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="#*|node()" name="copy">
<xsl:copy><xsl:apply-templates select="#*|node()" /></xsl:copy>
</xsl:template>
<xsl:template match="p" />
</xsl:stylesheet>
But this one does:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:template match="#*|node()" name="copy">
<xsl:copy><xsl:apply-templates select="#*|node()" /></xsl:copy>
</xsl:template>
<xsl:template match="xhtml:p" />
</xsl:stylesheet>
My problem and question is: How can I change the XSLT so that I do not have to add prefixes to all the XHTML elements and it still get to match them? From what I tried so far, adding a default namespace like <xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" /> does not achieve this.
Thanks for your help!
How can I change the XSLT so that I do not have to add prefixes to all the XHTML elements and it still get to match them?
This is possible, but I would recommens defining the namespace and using the preefix in referring to elements in this namespace:
<xsl:template match="*[local-name()='p']" />
Warning:
This technique can be safe only if it is guaranteed that there arent two elements with the same local-name() but in different namespaces.
I have a XML file with code like
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="rss2.xsl" type="text/xsl" media="screen"?> <rss version="2.0"> <channel>
<title>TITLE</title>
<description>Description</description>
<link>
some link
</link>
<copyright>Copyrights 2012, All Rights Reserved</copyright>
<item>
<title> title 1</title>
<description> desc</description>
<link>
some link
</link>
</item> </channel> </rss>
And an XSL file for this is
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<html>
<head>
<title>XML RSS Feed</title>
<link type="text/css" rel="stylesheet" href="rss_xsl.css" >
</head>
<body>
<h2>XML RSS Feed</h2>
<hr />
<div id="content">
<xsl:for-each select="rss/channel/item">
<div class="article">
<h3><xsl:value-of select="title"/></h3>
<p><xsl:value-of select="description"/></p>
</div>
</xsl:for-each>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The issue is when i comment the stylesheet code then chrome shows the feed. when i include the style the feeds are no more visible. How can this stop showing the feeds. is their some thing wrong with this inclusion of Style for XSL files..
Well the stylesheet markup is not well-formed, due to <link type="text/css" rel="stylesheet" href="rss_xsl.css" > which should be <link type="text/css" rel="stylesheet" href="rss_xsl.css"/>. Then I think the approach works when loading over HTTP. If you load the XML document from the file system then I think Chrome refuses to load the the stylesheet linked to, for security reasons. There might be command line options or settings to change the behavior.
I have an xhtml file that I'm attempting to transform such that:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>yada</title>
<meta.....>
</head>
<body>
<p>Something</p>
<p>awesome</p>
</body>
</html>
becomes a
<title>yada</title>
<meta.....>
<p>Something</p>
<p>awesome</p>
The key thing that I'm getting at is that the <head> and <body> tags are removed from the document. I don't want to run this through sed or awk to remove them.
Everything that I've tried either has the whole thing in html or converts it all into pure text.
Background on problem: I've got a backup of my blog written in multimarkdown, I'm hoping to put them into different format but I need to get over this issue first.
Note: I started off with the identity template.
something like this? (bear with me, its been ages since I've done XSL actively)
<xsl:for-each select="head">
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:for-each select="body">
<xsl:copy-of select="."/>
</xsl:for-each>
Sounds like you want the identity transform for everything below html and body:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/html|/html/head|/html/body">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Are you sure this isn't the usual namespace problem? Does the input really look like you showed us, or did you leave out the namespaces because you didn't realise they made all the difference?
how do i implement css in xsl file? i tried this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<link rel="stylesheet" type="text/css" href="dxsl.css"/>
<xsl:output method="html" />
but it threw the error:
XSLTProcessor::importStylesheet(): Found a top-level element link with null namespace URI
and
Warning: XSLTProcessor::transformToXml(): No stylesheet associated to this object
Your html (link tag) must be inside an xsl:template. The xsl:template must be inside an xsl:stylesheet.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/*//*[1]">
<link rel="stylesheet" type="text/css" href="dxsl.css"/>
</xsl:template>
</xsl:stylesheet>
If I understand you correctly, you wish for the output to have a particular stylesheet?
XSL is a language used to transform XML from one format to another (in a sense it's like applying a css stylesheet). What would happen in a typical use case is that you would take some xml file and use XSL to transform it, say to XHTML. In this output, you can include a stylesheet using the link element if you wanted, but XSL doesnt really make use of CSS as such. (So basically, try putting the CSS in the XSL as part of the transformation to have the XHTML output use it.)
If this is an XML document you simply need to include the reference to the XSL and it should handle the transformation for you automatically.
'link' is a HTML element and you're trying to use it as an XML one. XSL modifies input into another document. You don't use CSS in an XSL file. You insert it into an (X)HTML file and apply it there.
As another answer said, the link must be generated by the transform. Here's an example that generates a small HTML doc with link to CSS from a simple xml doc. The css path comes from the data as well.
Try this