I want to transform an input XML document into XHTML via XSLT. In my stylesheet I'm using xsl:output with the following attributes:
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />
The transformation into XTHML 1.0 Strict works fine when I use the XSLT Processor in editors like XML Copy Editor or Editix. It works as expected when I use the command line xsltproc, too.
But when I link my stylesheet ("myfile.xsl") into the original XML document ("myfile.xml") like this:
<?xml-stylesheet type="text/xsl" href="myfile.xsl"?>
if I try to watch now "myfile.xml" in the major browsers (Chrome, IE or Mozilla), none of them is capable of transforming the XML document in the expected XHTML. With Opera, however, it works perfectly.
Is there something wrong in my XSLT (namely in the xsl:output) or is this a flaw in the XSLT implementation of the major browsers (IE, Chrome, Mozilla)?
The problem occurs only when I use the attribute method="xml" in . If I use method="html", it works in all browsers. But I need to generate XHTML, not HTML, that's why I use method="xml" along with the doctype-system & doctype-public attributes in xsl:output
Well you haven't really told us in what way the browsers fail. If you want to create XHTML output then make sure you use the XHTML namespace for your result elements i.e. put
<xsl:stylesheet
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />
<xsl:template match="/">
<html>...<xsl:apply-templates/>...</html>
</xsl:template>
</xsl:stylesheet>
in your code to make sure the result elements are XHTML elements (and not XML elements in no namespace that happen to have local names like 'html' but are not recognizable as XHTML).
I am pretty sure that Firefox/Mozilla browsers that way with output method xml recognize the XHTML elements. And IE 9 and 10 as well I think, I am not sure older versions of IE with limited XHTML support will work.
To give you an example, the XML input http://home.arcor.de/martin.honnen/xslt/test2013040601.xml is transformed to xml output via http://home.arcor.de/martin.honnen/xslt/test2013040601.xsl and works fine with IE 10 and current version of Firefox and Chrome on Windows 8.
I believe most of the browsers don't serialize the output when running a transformation using the xml-stylesheet PI. They simply create a result tree and then render it. If they aren't serializing the result tree, they should quite rightly ignore the xsl:output declaration.
There are a few underlying issues with client-side XSLT:
The XHTML doctype URLs are blocked by the W3C in IE, so a patch is necessary
The XML serializer in Firefox is used to output XHTML, so it will fallback to text if the XHTML namespace is not used
The media-type attribute needs to be defined as text/html for Chrome
Here is a self-referencing stylesheet which will work when saved as html5.xml:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="html5.xml"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
>
<xsl:output method="xml" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="no" doctype-system="about:legacy-compat" />
<xsl:template match="xsl:stylesheet">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<xsl:text>hi</xsl:text>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Here are some unrelated questions which explain other cross-browser issues:
XML to XML transformation with XSLT in Firefox and IE
Using inline XSLT for an XML file
References
XSLT Security
Transformiix Test Cases
XML Conformance
Most browser only support XSLT 1.0, You should've a look at SaxonCE to add support for XSLT 2.0
Saxon-CE (client edition) is Saxonica's implementation of XSLT 2.0 for use on web browsers.
Features
Beware of the XPath 2.0 support.
Related
I'm working on a webscraping project on the following website http://www.comune.taranto.it/index.php/avvisi. I would like to extract the content of the first table and insert them into a Google Spreadsheet. I'm trying to use different xpath codes:
//td[contains(#class,'list-title')]/a/text()
//tbody[1]/tr/td/a/text()
//tr[contains(#class,'cat-list')]/td/a/text()
All of these codes work when I use the HTML debbugger of Chrome, but when I paste them into IMPORTXML, it returns N/A.
Can someone help me?
The website http://www.comune.taranto.it/index.php/avvisi returns invalid markup.
I just tried to fetch the website from console:
await fetch('http://www.comune.taranto.it/index.php/avvisi').then(res => res.text())
And I got:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it-it" lang="it-it" dir="ltr">
<head>
...
So <?xml version="1.0" encoding="utf-8"?> should not be there. That's why IMPORTXML can't parse it. To verify it I just temporary hosted website on repl.it with and without that xml declaration. And IMPORTXML was able to parse when the website was without it.
So what's the solution?
If you can then change the website to return a valid html
Or use Google App Scripts and write the code to parse the website
Or use some kind of proxy website that returns valid html
Since I learned to serve XHTML pages as XML, I have started noticing something odd: whenever I view an XHTML page in the Firefox source code viewer, the DOCTYPE is always marked as an error. According to the tooltip I get from mousing over it, the error in question is a "stray doctype". From what I understand, a "stray doctype" means that there is an extra DOCTYPE in the middle of the document where it doesn't belong, which is certainly not the case here.
Here's an example - this markup will pass validation, and display correctly in all modern browsers:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--FF source viewer will mark the preceding two lines as an error.-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type"
content="application/xhtml+xml; charset=utf-8" />
<title>Sample XHTML Page</title>
</head>
<body>
<p>This is an example.</p>
</body>
</html>
This error message is especially odd, considering that these pages pass validation perfectly, and that a single parsing error would normally break the page.
I am the developer of this feature. You have found a bug. (Filed just now.) Thanks.
View Source syntax highlighting is based on the HTML parser, because our XML parser is not suited for the purpose and XML is rare enough that it doesn't make sense to put resources into implementing proper XML View Source. Hence, the XML View Source feature is a hack on the HTML parser and this aspect doesn't work quite right.
The error appears because the file is saved as UTF-8 BOM instead of UTF-8. Open the file in Notepad and change its encoding.
In addition to #Public Sphere's answer.
This warning can also occur when using <!DOCTYPE html>.
Probably the same warning is then also shown for the <html>, <head> and <body> tags (stray start tag "html").
To check if UTF-8 BOM is the problem:
Click the 'network' tab
Click the first request
On right details panel, click 'Response' tab and expand 'Response Payload'
You'll see the raw response now.
A red dot is in front of the doctype line,
and on hover it displays "\ufeff"
To easily find the files that could cause the problem, you can, in Linux, use this grep to find all files with BOM:
grep -rl $'\xEF\xBB\xBF' .
Is there any way to include xml file in to another in Joomla 2.5 and up?
I am not asking how to write joomla xml params. Question is simple as title .
Is there a way to include one xml in to another in Joomla ?
I have 2 files templateDetails.xml and extend.xml
used these examples:
http://msdn.microsoft.com/en-us/library/aa302291.aspx
Can we import XML file into another XML file?
start code
templateDetails.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install PUBLIC "-//Joomla! 2.5//DTD template 1.0//EN" "http://www.joomla.org/xml/dtd/1.6/template-install.dtd" [
<!ENTITY extend SYSTEM "extend.xml">
]>
<extension version="2.5" type="template" client="site" method="upgrade">
<name>...</name>
<creationDate>...</creationDate>
<author>...</author>
<copyright>...</copyright>
<authorEmail>...</authorEmail>
<authorUrl>...</authorUrl>
<version>1.0</version>
<positions>
<position>top</position>
</positions>
<config>
<fields name="params">
<fieldset name="basic">
&extend;
</fieldset>
</fields>
</config>
</extension>
extend.xml:
<?xml version="1.0" encoding="utf-8"?>
<field name="somevar" type="list" default="2" label="My label" description="My desc">
<option value="1">Yes</option>
<option value="2">No</option>
</field>
I either made mistake somewhere or should use another approach. Any help is appreciated,
Unfortunately I don't think this is possible with Joomla. It is something I have looked at to reduce xml code duplication in Joomla components I am developing. I was searching Stack OVerflow to see if any solution was on here. The problem is in the way Joomla loads the xml files. It uses $xml = simplexml_load_file($file) to load files but to use entity expansion this would need to be changed to $xml = simplexml_load_file($file,null, LIBXML_NOENT). There are multiple locations where Joomla loads xml files so each would need to be changed. I don't know if there is a specific reason the Joomla developers did not use the extended form or may be I have missed something and there is a way to do this. I have it down as something to investigate further and possibly raise as a pull request for a later release of Joomla (I've checked in release 3.2.4 and it hasn't changed).
I submitted a sitemap to Google and I got this error.
Incorrect namespace
Your Sitemap or Sitemap index file doesn't properly declare the namespace. Expected: http://www.google.com/schemas/sitemap-image/1.1 Found: http://www.sitemaps.org/schemas/sitemap-image/1.1
I thought that sitemaps.org was okay. I took it from Google's example:
Google's sitemap example
What am I doing wrong? Any ideas?
Have you tried replacing
http://www.sitemaps.org/schemas/sitemap-image/1.1
with
http://www.google.com/schemas/sitemap-image/1.1
since that seem to be problem?
If you have and that didn't help, can you post your sitemap here? Include just a few url tags.
Update: This page may be of use: http://www.sitemaps.org/protocol.php. It's where I started when I wrote my first sitemap.
Another thought: In case you don't link directly to images or videos but only to html pages or php pages, you probably can remove
xmlns:image="http://www.sitemaps.org/schemas/sitemap-image/1.1"
and
xmlns:video="http://www.sitemaps.org/schemas/sitemap-video/1.1
I'm not using that code in my sitemap, and it works as it should.
Hello,
Actually the solution was replacing this:
<sitemapindex xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.sitemaps.org/schemas/sitemap/0.9/ https://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
With this:
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
And it works as expected and Google sitemap can be able to read the file.
Thank you
XML namespaces are used for providing uniquely named elements and attributes in an XML document.
Name conflicts in XML can easily be avoided using a name prefix.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <html> <body> <h2>My CD Collection</h2>
<table border="1">
<tr>
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each> </table> </body> </html> </xsl:template>
</xsl:stylesheet>
I am attempting to display a dynamically created SVG inline in a dojo based application and am running into some difficulty.
When I navigate directly to the SVG, it renders fine in Firefox 3.5/3.6 and Chrome, but when I inline it, verifying I have the right DOCTYPE and XML namespaces, both Firefox and Chrome just display a pile of text from within the SVG. I then attempted to change my content type served up to force it to be application/xhtml+xml but when forced into a XHTML valid mode, both Firefox and Chrome refuse to give dojo access to everything in the DOM that is required for it to work.
The start of my document is:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:xlink="http://www.w3.org/1999/xlink">
And my inline SVG starts as:
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="1394">
I have also attempted to display the SVG stand alone through an <img> tag, which seems to work fine in Chrome, but Firefox 3.5/3.6 refuses to display the SVG in a dijit.ContentPane, though again navigating directly to the document displays the picture. For this I used:
<img src="test_svg.php" />
And my standalone document starts with:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.0" width="480" height="1394">
And I set the following header:
Content-Type: image/svg+xml
I would use dojox.gfx but I have a rather lot of server side code to generate the SVG that I wouldn't be too keen on trying to translate to dojox.gfx and I am pretty sure that some of the styling I do with the SVG is not easily supported under dojox.gfx.
Just use <embed>.
<embed src="generated.svg" width="500" height="500">
BTW, this method even mentioned in SVG Primer. It is very easy to check if it works for you: http://srufaculty.sru.edu/david.dailey/svg/simplescript.html — taken directly from the SVG Primer. If you can see a quarter-circle it works.
Of course, going this route you are tying your application to SVG-capable browsers. No IE, no mobile browsers that support only Canvas.