Reputation: 1
I am using XML for the first time. To get around the Common Origin problem, I decided to use inline XSLT (and Schema, though this doesn't appear to be necessary. When I load my XML file into Firefox, the data is rendered exactly as required. When I use Chrome or Edge, no data is rendered - when I "Inspect" the page, I see the message "No matching selector or style".
I use the following code to declare the XSLT:
<?xml-stylesheet type = "text/xml" href = "#stylesheet"?>
<!DOCTYPE Ass8 [
<!ATTLIST xsl:stylesheet
id ID #REQUIRED>
]>
I have also tried using "application/xml" but with the same result.
My XSL is declared as follows:
<xsl:stylesheet id = "stylesheet"
version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns = "http://www.w3.org/1999/xhtml">
I had to add the last line (xhtml) to get it to work on Firefox.
Can anybody point me in the right direction, show me why I'm an idiot, etc.? I would be very grateful.
This is a shortened version of the code I'm using, which works on Firefox but not Chrome.
<?xml version = "1.0" encoding = "UTF-8" ?>
<?xml-stylesheet type = "text/xml" href = "#sheet1"?>
<!DOCTYPE dataWrapper [
<!ELEMENT xsl:stylesheet (#PCDATA)>
<!ATTLIST xsl:stylesheet
id ID #REQUIRED>
]>
<SS1:dataWrapper xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SS1 = "SS1:groupData" >
<!-- Add the Schema -->
<xsd:schema targetNamespace="SS1:dataWrapper">
<element name = "SS1:dataWrapper" type = "dataWrapperType"/>
<element name = "SS1:groupData" type = "groupDataType"/>
<!-- Now the simple elements -->
<xsd:element name = "SS1:fieldOne" type = "xsd:string"/>
<xsd:element name = "SS1:fieldTwo" type = "xsd:string"/>
<xsd:element name = "SS1:fieldThree" type = "xsd:positiveInteger"/>
<xsd:element name = "SS1:fieldFour" type = "xsd:positiveInteger"/>
<!-- Define the structure of the complex elements -->
<complexType name = "dataWrapperType">
<sequence>
<element ref = "groupDataType"/>
</sequence>
</complexType>
<complexType name = "groupDataType">
<sequence>
<xsd:element ref = "SS1:fieldOne"/>
<xsd:element ref = "SS1:fieldTwo"/>
<xsd:element ref = "SS1:fieldThree"/>
<xsd:element ref = "SS1:fieldFour"/>
</sequence>
</complexType>
</xsd:schema>
<!-- Add the XSLT -->
<xsl:stylesheet id = "sheet1"
version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns = "http://www.w3.org/1999/xhtml">
<xsl:output method = "html" doctype-system = "about:legacy-compat"
encoding = "UTF-8"/>
<xsl:template match = "/">
<!-- <xsl:apply-templates/> -->
<html>
<head>
<title>Assignment 8 Output</title>
</head>
<body>
<table>
<tr style = "color:white; background:blue">
<th>fieldOne</th>
<th>fieldTwo</th>
<th>fieldThree</th>
<th>fieldFour</th>
</tr>
<xsl:for-each select = "SS1:dataWrapper/SS1:groupData">
<tr style = "color:navy; background:aqua; text-align:center">
<td> <xsl:value-of select = "SS1:fieldOne"/> </td>
<td> <xsl:value-of select = "SS1:fieldTwo"/> </td>
<td> <xsl:value-of select = "SS1:fieldThree"/> </td>
<td> <xsl:value-of select = "SS1:fieldFour"/> </td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<SS1:groupData>
<SS1:fieldOne>Abc</SS1:fieldOne>
<SS1:fieldTwo>Def</SS1:fieldTwo>
<SS1:fieldThree>100</SS1:fieldThree>
<SS1:fieldFour>1000</SS1:fieldFour>
</SS1:groupData>
</SS1:dataWrapper>
Upvotes: 0
Views: 671
Reputation: 167506
Perhaps show us a complete but minimal sample, I have just tried to load
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="#sheet1"?>
<!DOCTYPE root [
<!ELEMENT xsl:stylesheet (#PCDATA)>
<!ATTLIST xsl:stylesheet
id ID #REQUIRED>
]>
<root>
<items>
<item>
<name>item 1</name>
</item>
<item>
<name>item 2</name>
</item>
</items>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" id="sheet1">
<xsl:template match="/">
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<xsl:apply-templates select="root/items"/>
</body>
</html>
</xsl:template>
<xsl:template match="items">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match="item">
<li>
<xsl:apply-templates/>
</li>
</xsl:template>
</xsl:stylesheet>
</root>
over a file: URI in current versions of Firefox, Chrome and Edge(Chromium based) on Windows 10 and also run the XML through xsltproc as a test for libxslt and the embedded stylesheet is applied and XML content is transformed to HTML and in the browsers rendered correctly.
As for your sample, I still don't see why you claim Firefox needs to have an XHTML namespace declaration; for the Chrome or Edge problems as far as I can tell you simply have allowed yourself too much liberty of whitespace inside the "data" part of the xml-stylesheet
pseudo processing instruction, if I don't use any excessive whitespace
<?xml version = "1.0" encoding = "UTF-8" ?>
<?xml-stylesheet type="text/xml" href="#sheet1"?>
<!DOCTYPE SS1:dataWrapper [
<!ELEMENT xsl:stylesheet (#PCDATA)>
<!ATTLIST xsl:stylesheet
id ID #REQUIRED>
]>
<SS1:dataWrapper xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SS1 = "SS1:groupData" >
<!-- Add the Schema -->
<xsd:schema targetNamespace="SS1:dataWrapper">
<element name = "SS1:dataWrapper" type = "dataWrapperType"/>
<element name = "SS1:groupData" type = "groupDataType"/>
<!-- Now the simple elements -->
<xsd:element name = "SS1:fieldOne" type = "xsd:string"/>
<xsd:element name = "SS1:fieldTwo" type = "xsd:string"/>
<xsd:element name = "SS1:fieldThree" type = "xsd:positiveInteger"/>
<xsd:element name = "SS1:fieldFour" type = "xsd:positiveInteger"/>
<!-- Define the structure of the complex elements -->
<complexType name = "dataWrapperType">
<sequence>
<element ref = "groupDataType"/>
</sequence>
</complexType>
<complexType name = "groupDataType">
<sequence>
<xsd:element ref = "SS1:fieldOne"/>
<xsd:element ref = "SS1:fieldTwo"/>
<xsd:element ref = "SS1:fieldThree"/>
<xsd:element ref = "SS1:fieldFour"/>
</sequence>
</complexType>
</xsd:schema>
<!-- Add the XSLT -->
<xsl:stylesheet id = "sheet1"
version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="SS1">
<xsl:output method = "html" version="5" doctype-system = "about:legacy-compat" encoding = "UTF-8"/>
<xsl:template match = "/">
<html>
<head>
<title>Assignment 8 Output</title>
</head>
<body>
<table>
<tr style = "color:white; background:blue">
<th>fieldOne</th>
<th>fieldTwo</th>
<th>fieldThree</th>
<th>fieldFour</th>
</tr>
<xsl:for-each select = "SS1:dataWrapper/SS1:groupData">
<tr style = "color:navy; background:aqua; text-align:center">
<td> <xsl:value-of select = "SS1:fieldOne"/> </td>
<td> <xsl:value-of select = "SS1:fieldTwo"/> </td>
<td> <xsl:value-of select = "SS1:fieldThree"/> </td>
<td> <xsl:value-of select = "SS1:fieldFour"/> </td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<SS1:groupData>
<SS1:fieldOne>Abc</SS1:fieldOne>
<SS1:fieldTwo>Def</SS1:fieldTwo>
<SS1:fieldThree>100</SS1:fieldThree>
<SS1:fieldFour>1000</SS1:fieldFour>
</SS1:groupData>
</SS1:dataWrapper>
then the XSLT is applied in Chrome, Chromium based Edge and Firefox.
Keep in mind that the "data" part of a PI (processing instruction) often looks like the attribute/value pairs of an XML element markup but in general it is not; it seems that libxml/libxslt, the XML parser/XSLT processor components used by Chrome and Chromium under the hood do not allow any excessive whitespace in there if you want them to parse your PI correctly to find the embedded stylesheet.
Upvotes: 0