Reputation: 2654
I am using xslt styelsheets to apply to xml, chrome and ie render correctly, however firefox seems to add xml tag
transformiix:result
How can i get this removed in firefox. It is affecting my javascript. I tried to do work around but its not working anymore
workaround
if($('body').length == 0){ // firefox is transforming xsl differently so this fix is needed
var head = $("#top_section")
var $set = $( document ).children();
$set = $set.children();
for(var i=1, len = $set.length; i < len; i +=5){
$set.slice(i, i+6).wrapAll('<body />');
}
}
update
I am running php7 with apache.
xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/xslt/user_services_owners.xsl"?>
<response>
<header>
<error>false</error>
<message>success</message>
<api_status>1</api_status>
<api_response>success</api_response>
<http_status>200</http_status>
<http_response>ok</http_response>
<format>xml</format>
<csrf>946dc689cae6c5d0ae3fcf01de951493</csrf>
<token>946dc689cae6c5d0ae3fcf01de951493</token>
<user>UddinS2</user>
<title>Manage Service, Project, Programme</title>
<description>List, add, edit, and remove services, projects and programmes</description>
<nav>
<container>
<title>Users</title>
<link>#</link>
<theme>#007c92</theme>
<sub_modules>
<title>Getting Started</title>
<link>#</link>
<theme>#007c92</theme>
<menuitem>
<title>File - CM Template v6.3</title>
<link>/library/templates/FW-LB-CommsMatrix-Template-v6.3.xls</link>
</menuitem>
<menuitem>
<title>Sudo Group Access</title>
<link>/sudo_group_access.php?csrf=946dc689cae6c5d0ae3fcf01de951493</link>
</menuitem>
</sub_modules>
</container>
</nav>
<server>1</server>
<version>5.1</version>
</header>
<body>
<recordset>
<record>
<ID>121</ID>
<SERVICE_ID>201</SERVICE_ID>
<NAME>UddinS2</NAME>
<TYPE>owner</TYPE>
<SERVICE>* Ad-hoc Submission</SERVICE>
</record>
<metadata>
<num_rows>1</num_rows>
</metadata>
</recordset>
</body>
</response>
/xslt/user_services_owners.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="header.xsl" />
<!-- <xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes" indent="no" media-type="text/html" />-->
<xsl:output method="html" indent="yes" encoding="iso-8859-1" media-type="html" doctype-public="-//W3C//DTD HTML 4.0//EN" />
<xsl:template match="body">
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
</div>
</div>
<!-- content of other element -->
<xsl:apply-templates select="footer" />
</xsl:template>
</xsl:stylesheet>
header.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- header.xsl -->
<xsl:template match="header">
<!-- content of header -->
<HEAD>
</HEAD>
<div class="container-fluid" id="top_section">
</div>
<!-- Sidebar -->
<div id="sidebar-wrapper" class="hidden-print">
</div>
<!-- Modal -->
<div id="myModalError" class="modal fade" role="dialog">
</div>
</xsl:template>
<xsl:template name="footer">
<FOOTER>
</FOOTER>
</xsl:template>
</xsl:stylesheet>
In firefox i see the below code after using my workaround.
<transformiix:result><head>....</head><body>....</body></transformiix:result>
I am using php to generate the xml which i put above which is echoed to browser. the browser translates the stylesheet and the workaround is triggered on document.ready
only in firefox, which places the div's in the correct place inside body tag. without it there is no body tag. the problem is: jquery cannot locate body because it is encapsulated with transformiix in firefox
Upvotes: 0
Views: 1058
Reputation: 167716
Your current XSLT does not create a HTML root element so change your main stylesheet to e.g.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="header.xsl" />
<xsl:output method="html" indent="yes" doctype-system="about:legacy-doctype"/>
<xsl:template match="/">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="body">
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
</div>
</div>
<!-- content of other element -->
<xsl:apply-templates select="footer" />
</xsl:template>
</xsl:stylesheet>
That should avoid the problem with the transformiix:result
element being added. I think there are other issues with your approach that will not result in valid HTML but it is not as easy fixing them as you seem to want to output HTML result elements like div
elements from different templates for the header and the body.
Upvotes: 1