Hallo,
ich habe eine Frage bzgl. XML und XSL die zusammen im Browser gerendert werden:
Ist es möglich eine XML-Struktur im Browser zu laden, sie dann erst via Javascript zu ändern und dann anschließend mit einer XSL direkt im Browser zu rendern? Kennt jemand für sowas ein Beispiel?
Viele Grüße
Michael
Hier mein Code für Firefox bisher (wie kann ich den jetzt noch erweitern, so dass ich der XML-Struktur noch ein Tag <test>txt</test> hinzufügen kann:
Die XML:
<?xml version="1.0" encoding="UTF-16"?>
<!DOCTYPE gruss SYSTEM "browser.dtd">
<BirdInfo>
Blblabla
</BirdInfo>
Die XSL:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<p align="left" style="color:red">
<xsl:value-of select="." />
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Die verarbeitende HTML:
<html>
<head>
<script language="javascript">
//Create an XSLT processor instance
var processor = new XSLTProcessor();
//Create an empty XML document for the XSLT transform
var transform = document.implementation.createDocument("", "", null);
//Load the XSLT
function loadXML(){
transform.onload = loadTransform;
transform.load("browser.xsl");
}
//Triggered once the XSLT document is loaded
function loadTransform(){
//Attach the transform to the processor
processor.importStylesheet(transform);
source = document.implementation.createDocument("", "", null);
source.load("browser.xml");
source.onload = runTransform;
}
//Triggered once the source document is loaded
function runTransform(){
//Run the transform, creating a fragment output subtree that
//can be inserted back into the main page document object (given
//in the second argument)
var frag = processor.transformToFragment(source, document);
//insert the result subtree into the document, using the target element ID
document.getElementById('updateTarget').appendChild(frag);
}
</script>
</head>
<body>
<input type="submit" value = "load" onclick="loadXML();">
<p><div id="updateTarget"/></p>
</body>
</html>