asked on
XSLT and XML content using JavaScript not loading in Microsoft Edge browser, it's working fine on Internet Explorer.
Hi all,
XSLT and XML content not loading in Microsoft Edge browser, it's working fine on Internet Explorer.
Please let me know how to fix the issue on Edge Browser.
Thanks
Please find the Javascript code, xml and xsl files.
tree.js
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<SCRIPT LANGUAGE="Javascript" type="text/javascript">
function initialize()
{
var xmlDoc
var xslDoc
xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
xmlDoc.async = false;
xslDoc = new ActiveXObject('Microsoft.XMLDOM')
xslDoc.async = false;
xmlDoc.load("tree/tree.xml")
xslDoc.load("tree/tree.xsl")
folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc)
}
</SCRIPT>
</head>
<body onload="initialize()">
<form id="form1" runat="server">
<DIV id="folderTree" STYLE="PADDING-TOP: 4px"></DIV>
</form>
</body>
</html>
___________________________________
tree.xml in the attachmenttree.xml
___________________
tree.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="JavaScript">
<xsl:template match="tree">
<xsl:apply-templates select="entity"/>
</xsl:template>
<xsl:template match="entity">
<div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return false" ondragstart="return false">
<xsl:attribute name="image"><xsl:value-of select="image"/></xsl:attribute>
<xsl:attribute name="imageOpen"><xsl:value-of select="imageOpen"/></xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="id">f<xsl:value-of select="@id"/></xsl:attribute> <!--pre-pend "f" to entity id value. -->
<!-- <xsl:attribute name="folderName"><xsl:value-of select="description/."/></xsl:attribute>-->
<xsl:attribute name="keyId"><xsl:value-of select="@key-id"/></xsl:attribute>
<xsl:attribute name="linkPageName"><xsl:value-of select="@link-page-name"/></xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="STYLE">
padding-left: 20px;
cursor: hand;
<xsl:if expr="depth(this) > 2">
display: none;
</xsl:if>
</xsl:attribute>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle">
<img border="0" id="image">
<xsl:attribute name="SRC">
<xsl:value-of select="image"/>
</xsl:attribute>
</img>
</td>
<td valign="middle" nowrap="true">
<xsl:attribute name="STYLE">
padding-left: 7px;
font-family: Verdana;
font-size: 11px;
font-color: black;
</xsl:attribute>
<xsl:value-of select="description"/></td>
</tr>
</table>
<xsl:apply-templates select="entity"/>
</div>
</xsl:template>
</xsl:stylesheet>
Also you stylesheet may not be accepted as valid in those browsers. I could not find the exact reason.
check the namespace: xmlns:xsl="http://www.w3.org/TR/WD-xsl"
the namespace for an xslt is xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
Microsoft was the only company that ever published a processor for the XSLT working draft
(they were to early, too many changes to the standard would happen after)
They kept the working draft XSLT processor available (since there were too many customers already relying on it) alongside the standard XSLT processor after in msxml and IE. I believe they are now dropping support
If ever you want to use your stylesheet in edge or chrome... you will need to change the namespace
other changes you will need
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
add the version and loose the language attributeAnd you need to fix this line
<xsl:if expr="depth(this) > 2">
the @expr is no longer allowed, this needs to be testand in order to have access to the depth function, you need to extend the processor to have access to the scripting engine. But that would bind your stylesheet to a specific processor again
If I understand your code well enough, I guess this should work
<xsl:if test="count(ancestor::entity) > 2">
ActiveX end of life was reached a few years ago for security reason.
So it may only work with old browsers / old OS and this would not be recommended for security reason.
There is no real replacement for ActiveX.
Maybe you can check advance Javascript (server side) to find so sort of replacement
or maybe create an Apps using React Native .
An old article that explain this
https://blogs.windows.com/msedgedev/2015/05/06/a-break-from-the-past-part-2-saying-goodbye-to-activex-vbscript-attachevent/
ASKER
On clicking of any node, this is error showing. Please help me what needs to be done to fix this issue.
'Uncaught TypeError: entity.childNodes is not a function
at collapse (tree.js)
at clickOnEntity (tree.js)
at expand(tree.js)
at expandAll(tree.js)
at HTMLDivElement.onclick
I want the data to be collapsed on page load.
like. Tree should look like
+ Sales
+ Service
Clicking on Sales expand that node
-Sales
- A_test1_test1
+ A_Product1
+ Service
tree.xml
tree.xsl
tree.js
function loadXMLDoc(filename) {
if (window.ActiveXObject) {
xhttp = new ActiveXObject("Microsoft.XMLDOM");
}
else {
xhttp = new XMLHttpRequest();
}
xhttp.open("GET", filename, false);
try { xhttp.responseType = "msxml-document" } catch (err) { } // IE11
xhttp.send("");
return xhttp.responseXML;
}
function initialize() {
xml = loadXMLDoc("tree/tree.xml");
xsl = loadXMLDoc("tree/tree.xsl");
// code for IE
if (window.ActiveXObject || "ActiveXObject" in window) {
alert("ie")
folderTree.innerHTML = xml.documentElement.transformNode(xsl)
}
// code for Edge, etc.
else if (document.implementation && document.implementation.createDocument) {
alert("edge")
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml, document);
document.getElementById("folderTree").appendChild(resultDocument);
}
}
function LinkToForms(keyId, pageName) {
if ((keyId != null && keyId != "") && (pageName != null && pageName != "") ) {
parent.frameName2.location.href = pageName + '?PrimaryKeyID=' + keyId;
}
return true;
}
function clickOnEntity(entity) {
LinkToForms(entity.keyId, entity.linkPageName);
if(entity.open == "false") {
expand(entity, true)
}
else {
collapse(entity)
}
window.event.cancelBubble = true
}
function redirect(pageName) {
//Redirect to new page in same window.
self.location.href = pageName;
}
function expand(entity) {
var oImage
oImage = entity.childNodes(0).all["image"]
oImage.src = entity.imageOpen
for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes(i).tagName == "DIV") {
entity.childNodes(i).style.display = "block"
}
}
entity.open = "true"
}
function collapse(entity) {
var oImage
var i
oImage = entity.childNodes(0).all["image"]
oImage.src = entity.image
// collapse and hide children
for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes(i).tagName == "DIV") {
if(entity.id != "folderTree") entity.childNodes(i).style.display = "none"
collapse(entity.childNodes(i))
}
}
entity.open = "false"
}
function expandAll(entity) {
var oImage
var i
expand(entity, false)
// expand children
for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes(i).tagName == "DIV") {
expandAll(entity.childNodes(i))
}
}
}
ASKER
Please find the latest code of javascript. Data is showing in edge browser. Node clicks are not working. Please look into the javascript file and let me know how to fix the issue. None of the javascript functions are working now in edge browser.
Error : 'Uncaught TypeError: entity.childNodes is not a function
at collapse (tree.js)
at clickOnEntity (tree.js)
at expand(tree.js)
at expandAll(tree.js)
at HTMLDivElement.onclick
tree.js
ASKER
Please find the latest code of javascript. Data is showing in edge browser. Node clicks are not working. Please look into the javascript file and let me know how to fix the issue. None of the javascript functions are working now in edge browser.
Please help me.
Error : 'Uncaught TypeError: entity.childNodes is not a function
at collapse (tree.js)
at clickOnEntity (tree.js)
at expand(tree.js)
at expandAll(tree.js)
at HTMLDivElement.onclick
tree.js
tree.js is a very old script (8 years) and it now archived (the author stop the dev).
So this is normal that the script is not compatible with newest browser.
I would replace the script by another one
Maybe JStree https://github.com/vakata/jstree/
Other
Jqtree https://mbraak.github.io/jqTree/
jQuery TreeView https://github.com/HasanDelibas/jQueryTreeView
Fancy tree https://github.com/mar10/fancytreeTree view https://github.com/vsvvssrao/TreeView
the biggest issues were the collections and .all instead of using array notation
I also changed the id="image" to class="image" in the xsl, since IDs need to be unique
https://plungjan.name/ee/xmlxsl/
//function initialize() {
// var xmlDoc
// var xslDoc
// xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
// xmlDoc.async = false;
// xslDoc = new ActiveXObject('Microsoft.XMLDOM')
// xslDoc.async = false;
// xmlDoc.load("tree/tree.xml")
// xslDoc.load("tree/tree.xsl")
// folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc)
// }
var xsl;
var xsltProcessor = new XSLTProcessor();
var myDOM;
var xmlDoc;
function initialize() {
// load the xslt file
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "tree/tree.xsl", false);
myXMLHTTPRequest.send(null);
xsl = myXMLHTTPRequest.responseXML;
xsltProcessor.importStylesheet(xsl);
// load the xml file
myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "tree/tree.xml", false);
myXMLHTTPRequest.send(null);
xmlDoc = myXMLHTTPRequest.responseXML;
var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
document.getElementById("folderTree").textContent = "";
myDOM = fragment;
document.getElementById("folderTree").appendChild(fragment);
// collapse
const divs = document.querySelectorAll("div"); // newer browsers can do forEach here
for (var i=0;i<divs.length;i++) collapse(divs[i]);
}
function LinkToForms(keyId, pageName) {
if ((keyId != null && keyId != "") && (pageName != null && pageName != "")) {
//This links the category/product information to the admin screens using it's primary key.;
parent.frameName2.location.href = pageName + '?PrimaryKeyID=' + keyId;
}
return true;
}
function clickOnEntity(entity) {
LinkToForms(entity.keyId, entity.linkPageName);
if (entity.open == "false") {
expand(entity, true)
} else {
collapse(entity)
}
window.event.cancelBubble = true
}
function redirect(pageName) {
//Redirect to new page in same window.
self.location.href = pageName;
}
function expand(entity) {
var oImage, i;
oImage = entity.querySelector(".image")
oImage.src = entity.imageOpen
for (i = 0; i < entity.childNodes.length; i++) {
if (entity.childNodes[i].tagName == "DIV") {
entity.childNodes[i].style.display = "block"
}
}
entity.open = "true"
}
function collapse(entity) {
var oImage, i;
oImage = entity.querySelector(".image")
oImage.src = entity.image
// collapse and hide children
for (i = 0; i < entity.childNodes.length; i++) {
if (entity.childNodes[i].tagName == "DIV") {
if (entity.id != "folderTree") entity.childNodes[i].style.display = "none"
collapse(entity.childNodes[i])
}
}
entity.open = "false"
}
function expandAll(entity) {
var oImage, i;
expand(entity, false)
// expand children
for (i = 0; i < entity.childNodes.length; i++) {
if (entity.childNodes[i].tagName == "DIV") {
expandAll(entity.childNodes[i])
}
}
}
window.addEventListener("load", initialize)
ASKER
I cannot use any extra plugin.
Please find my code Javascript, xml and xsl files
tree.js
tree.xsl
tree.xml
Tree data start coming, but none of the javascript functions are working. Its not passing any values.
'Uncaught TypeError: entity.childNodes is not a function
at collapse (tree.js)
at clickOnEntity (tree.js)
at expand(tree.js)
at expandAll(tree.js)
at HTMLDivElement.onclick
I want the data to be collapsed on page load.
like. Tree should look like
+ Sales
+ Service
Clicking on Sales expand that node
-Sales
- A_test1_test1
+ A_Product1
+ Service
entity.childNodes(0)
byentity.childNodes[0]
This will require some adjustment to replace () by []
To collapse just do
document.getElementById("folderTree").appendChild(fragment);
const divs = document.querySelectorAll("div"); // newer browsers can do forEach here
for (var i=0;i<divs.length;i++) collapse(divs[i]);
ASKER
1. on page load. All nodes are collapsed and only parent nodes will display Service and Sales with plus image. Currently nodes are expanded on page load.
2. click on any of these nodes, will open the page in the right frame passing id and page name. ClickOnEntity is the function. currently its not working. Also, node will expand one level. expanded node image changes to minus image.
Please check the layouts and how to fix these issues.
Highly appreciate for your help.
Thanks
Tree_IE_Layout.docx
Tree_EdgeBrowser_Layout.docx
TestXMLInEdge.zip
You get "undefined" in the src here
<img border="0" class="image">
<xsl:attribute name="src">
<xsl:value-of select="image" />
</xsl:attribute>
</img>
<xsl:copy-of select="$image" />
and the JS to use getAttribute
https://plungjan.name/ee/xmlxsl/
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="tree">
<xsl:apply-templates select="entity"/>
</xsl:template>
<xsl:template match="entity">
<xsl:variable name="image"><xsl:value-of select="image"/></xsl:variable>
<xsl:variable name="imageOpen"><xsl:value-of select="imageOpen"/></xsl:variable>
<div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return false" ondragstart="return false">
<xsl:attribute name="image"><xsl:copy-of select="$image" /></xsl:attribute>
<xsl:attribute name="imageOpen"><xsl:copy-of select="$imageOpen" /></xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="id">f<xsl:value-of select="@id"/></xsl:attribute> <!--pre-pend "f" to entity id value. -->
<!-- <xsl:attribute name="folderName"><xsl:value-of select="description/."/></xsl:attribute>-->
<xsl:attribute name="keyId"><xsl:value-of select="@key-id"/></xsl:attribute>
<xsl:attribute name="linkPageName"><xsl:value-of select="@link-page-name"/></xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="style">
padding-left: 20px;
cursor: hand;
<xsl:if test="count(ancestor::entity) > 2">
display: none;
</xsl:if>
</xsl:attribute>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle">
<img border="0" class="image">
<xsl:attribute name="src">
<xsl:copy-of select="$image" />
</xsl:attribute>
</img>
</td>
<td valign="middle" nowrap="true">
<xsl:attribute name="style">
padding-left: 7px;
font-family: Verdana;
font-size: 11px;
font-color: black;
</xsl:attribute>
<xsl:value-of select="description"/></td>
</tr>
</table>
<xsl:apply-templates select="entity"/>
</div>
</xsl:template>
</xsl:stylesheet>
//function initialize() {
// var xmlDoc
// var xslDoc
// xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
// xmlDoc.async = false;
// xslDoc = new ActiveXObject('Microsoft.XMLDOM')
// xslDoc.async = false;
// xmlDoc.load("tree/tree.xml")
// xslDoc.load("tree/tree.xsl")
// folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc)
// }
var xsl;
var xsltProcessor = new XSLTProcessor();
var myDOM;
var xmlDoc;
function initialize() {
console.log("edge")
// load the xslt file
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "tree/tree.xsl", false);
myXMLHTTPRequest.send(null);
xsl = myXMLHTTPRequest.responseXML;
xsltProcessor.importStylesheet(xsl);
// load the xml file
myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "tree/tree.xml", false);
myXMLHTTPRequest.send(null);
xmlDoc = myXMLHTTPRequest.responseXML;
var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
document.getElementById("folderTree").textContent = "";
myDOM = fragment;
document.getElementById("folderTree").appendChild(fragment);
const divs = document.querySelectorAll("div"); // newer browsers can do forEach here
for (var i=0;i<divs.length;i++) collapse(divs[i]);
}
function LinkToForms(keyId, pageName) {
if ((keyId != null && keyId != "") && (pageName != null && pageName != "") ) {
//This links the category/product information to the admin screens using it's primary key.;
parent.frameName2.location.href = pageName + '?PrimaryKeyID=' + keyId;
}
return true;
}
function clickOnEntity(entity) {
LinkToForms(entity.keyId, entity.linkPageName);
if(entity.open == "false") {
expand(entity, true)
}
else {
collapse(entity)
}
window.event.cancelBubble = true
}
function redirect(pageName) {
//Redirect to new page in same window.
self.location.href = pageName;
}
function expand(entity) {
var oImage, i;
oImage = entity.querySelector(".image")
oImage.src = entity.getAttribute('imageOpen');
for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes[i].tagName == "DIV") {
entity.childNodes[i].style.display = "block"
}
}
entity.open = "true"
}
function collapse(entity) {
var oImage, i;
oImage = entity.querySelector(".image")
oImage.src = entity.getAttribute('image')
// collapse and hide children
for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes[i].tagName == "DIV") {
if(entity.id != "folderTree") entity.childNodes[i].style.display = "none"
collapse(entity.childNodes[i])
}
}
entity.open = "false"
}
function expandAll(entity) {
var oImage, i;
expand(entity, false)
// expand children
for(i=0; i < entity.childNodes.length; i++) {
if(entity.childNodes[i].tagName == "DIV") {
expandAll(entity.childNodes[i])
}
}
}
window.addEventListener("load",initialize)
ASKER
On Page load, its still showing the tree in expanded mode , so I modify this section in xsl.
<xsl:if test="count(ancestor::entity) > 2"> to <xsl:if test="count(ancestor::entity) > 0">
This is just showing two parent nodes Service and Sales with plus image.
Issue1 : To expand the tree first time, why I need to click the node Service or Sales two times. After that its working fine.
Issue 2: Also, its not opening the pages on the right frame on click of node. Node click should have page information and node id information. Its calling 'ClickonEntity' function.
Error: Cannot set properties of null (setting 'src') at collapse at initialize at onload.
thanks
ASKER
KeyId , Page Name information is coming from xml for each node.
function LinkToForms(keyId, pageName) { if ((keyId != null && keyId != "") && (pageName != null && pageName != "") ) { parent.frameName2.location.href = pageName + '?PrimaryKeyID=' + keyId; } return true; } function clickOnEntity(entity) { LinkToForms(entity.keyId, entity.linkPageName); if(entity.open == "false") { expand(entity, true) } else { collapse(entity) } window.event.cancelBubble = true } function redirect(pageName) { //Redirect to new page in same window. self.location.href = pageName; }
Thanks a lot.
Again you need getAttribute
https://plungjan.name/ee/xmlxsl/
LinkToForms(entity.getAttribute("keyId"), entity.getAttribute("linkPageName"));
I recommend to use data-attributes instead. then you can use
entity.dataset.linkPageNam
ASKER
Everything is working fine. Only one issue:
I tried everything. I am not sure what is missing. On Page load, it's showing nodes in expanded mode. I want a tree in collapse mode. Only Parent nodes need to display.
+ Service
+ Sales
Please find the code in the zip file.
TestXMLInEdge.zip
Thanks a lot for all the help.
https://plungjan.name/ee/xmlxsl1/
What is swapClass and why do you not have an image attribute
Why do you not use my code which works?
https://plungjan.name/ee/xmlxsl/
ASKER
Thanks
ASKER
Problem was coming as my HTML files have multiple <DIV's>.
Its working perfectly.