R
RobG
I am loading local XML files into an iFrame by simply setting its src
attribute to the URL of the xml file.
To get the files to display the way I want, I manually added a style
element to the top of the files, e.g.
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="validationReportNS.xsl"?>
<ValidationReport xmlns="..." id="...">
...
</ValidationReport>
however that is annoying - what I'd like to do is set the style sheet
using a function when the document is loaded. I've been trying
something like:
function loadFile(sourceID, targetID) {
var source = document.getElementById(sourceID);
var target = document.getElementById(targetID);
target.src = source.value;
addStyleSheet(targetID);
}
function addStyleSheet(id) {
var el = document.getElementById(id);
var xmlDoc = el.contentDocument;
var ss = xmlDoc.createElement('xml-stylesheet')
ss.type="text/xsl";
ss.href="validationReportNS.xsl";
// The following line is supposed to insert the stylesheet
xmlDoc.insertBefore(ss, xmlDoc.firstChild.nextSibling)
}
using a file input, button to call the function and an iFrame to
display it, e.g.
<div>
<input type="file" id="inp0">
<input type="button" value="Load"
onclick="loadFile('inp0', 'if0');">
<div style="height: 900px;">
<iframe id="if0" width="90%" height="90%"></iframe>
</div>
Is what I am trying to do possible using the method above? Or do I
have to load the document as an XML document, then add the style
element, then add it to the iFrame?
Any hints?
attribute to the URL of the xml file.
To get the files to display the way I want, I manually added a style
element to the top of the files, e.g.
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="validationReportNS.xsl"?>
<ValidationReport xmlns="..." id="...">
...
</ValidationReport>
however that is annoying - what I'd like to do is set the style sheet
using a function when the document is loaded. I've been trying
something like:
function loadFile(sourceID, targetID) {
var source = document.getElementById(sourceID);
var target = document.getElementById(targetID);
target.src = source.value;
addStyleSheet(targetID);
}
function addStyleSheet(id) {
var el = document.getElementById(id);
var xmlDoc = el.contentDocument;
var ss = xmlDoc.createElement('xml-stylesheet')
ss.type="text/xsl";
ss.href="validationReportNS.xsl";
// The following line is supposed to insert the stylesheet
xmlDoc.insertBefore(ss, xmlDoc.firstChild.nextSibling)
}
using a file input, button to call the function and an iFrame to
display it, e.g.
<div>
<input type="file" id="inp0">
<input type="button" value="Load"
onclick="loadFile('inp0', 'if0');">
<div style="height: 900px;">
<iframe id="if0" width="90%" height="90%"></iframe>
</div>
Is what I am trying to do possible using the method above? Or do I
have to load the document as an XML document, then add the style
element, then add it to the iFrame?
Any hints?