Hallo,
<xsl:param name="paramter" />
Das ist eigentlich genau das was ich brauche
schade nur das Browser das nicht über die URL beschicken können.
Bleibt wohl nur der Aufbau über den DOM-tree aus den Beispielen.
Gibt es das:
http://www.datenverdrahten.de/iproxslt/tourdaten/iejs/index.htm
auch mit einem Browser unabhängigen Ansatz?
Nein. Weil der IE und Mozilla hier doch wieder verschiedene Wege gehen.
Hier ein Beispiel für beide Browser (ich habe aber keine Lust gehabt jetzt eine Browserabfrage einzubauen, die Namen der xml & xsl Datei muss du dann für dich anpassen):
Hoffe es hilft dir
Grüße
Thomas
----------------- xml (book-review.xml) --------------------
<?xml version='1.0'?>
<book-review>
<book>
<title>A Good Book</title>
<author>The Good Writer</author>
<publisher>The Publisher</publisher>
<date>A Good Day</date>
<review>
<title>A Good Book</title> by <author>The Good Writer</author>,
published by <publisher>The Publisher</publisher> on <date>A
Good Day</date>, is indeed a good book.
</review>
</book>
<book>
<title>A Bad Book</title>
<author>The Bad Writer</author>
<publisher>The Publisher</publisher>
<date>A Bad Day</date>
<review>
<title>A Bad Book</title> by <author>The Bad Writer</author>,
published by <publisher>The Publisher</publisher> on <date>A Bad
Day</date>, is indeed a bad book.
</review>
</book>
<book>
<title>A So-so Book</title>
<author>The So-so Writer</author>
<publisher>The Publisher</publisher>
<date>A So-so Day</date>
<review>
<title>A So-so Book</title> by <author>The So-so Writer</author>,
published by <publisher>The Publisher</publisher> on
<date>A So-so Day</date>, is indeed a so-so book.
</review>
</book>
</book-review>
--------------------- xsl (book-review.xsl) -----------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="title" />
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates select="//book[title=$title]" />
</body>
</html>
</xsl:template>
<xsl:template match="book">
<table>
<tr>
<td style="font-weight:bold">Titel:</td>
<td><xsl:apply-templates select="title"/></td>
</tr>
<tr>
<td style="font-weight:bold">Autor:</td>
<td><xsl:apply-templates select="author"/></td>
</tr>
<tr>
<td style="font-weight:bold">Datum:</td>
<td><xsl:apply-templates select="date"/></td>
</tr>
<tr>
<td style="font-weight:bold">Verlag:</td>
<td><xsl:apply-templates select="publisher"/></td>
</tr>
<tr>
<td style="font-weight:bold">Rezension:</td>
<td><xsl:apply-templates select="review"/></td>
</tr>
</table>
</xsl:template>
<xsl:template match="title">
<span><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="author">
<span><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="publisher">
<span><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="date">
<span><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="review">
<p><xsl:apply-templates /></p>
</xsl:template>
</xsl:stylesheet>
------------------- html -----------------------
<html>
<head>
<script language="JavaScript" type="text/javascript">
/* FÜR DEN IE */
/*
var objSrcTree, ObjXSLT, objCache;
function init()
{
objSrcTree = new ActiveXObject('MSXML2.DOMDocument.4.0');
objSrcTree.async = false;
objSrcTree.load('book-review.xml');
objXSLT=new ActiveXObject('MSXML2.FreeThreadedDOMDocument.4.0');
objXSLT.async = false;
objXSLT.load('book-review.xsl');
objCache = new ActiveXObject("Msxml2.XSLTemplate.4.0");
objCache.stylesheet = objXSLT;
output.innerHTML = "Select a book above to read the review!";
}
function show(title)
{
var objXSLTProc = objCache.createProcessor();
objXSLTProc.input = objSrcTree;
objXSLTProc.addParameter("title", title, "");
objXSLTProc.transform();
output.innerHTML = objXSLTProc.output;
}
*/
/* FÜR MOZILLA */
var xslStylesheet;
var xsltProcessor = new XSLTProcessor();
var myDOM;
var xmlDoc;
function init()
{
// load the xslt file
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "book-review.xsl", false);
myXMLHTTPRequest.send(null);
xslStylesheet = myXMLHTTPRequest.responseXML;
xsltProcessor.importStylesheet(xslStylesheet);
// load the xml file
myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "book-review.xml", false);
myXMLHTTPRequest.send(null);
xmlDoc = myXMLHTTPRequest.responseXML;
document.getElementById("output").innerHTML = "Select a book above to read the review!";
}
function show(title)
{
var myParam = xsltProcessor.getParameter(null, "title");
xsltProcessor.setParameter(null, "title", title);
var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
myDOM = fragment;
document.getElementById("output").innerHTML = "";
document.getElementById("output").appendChild(fragment);
}
</script>
<title>XML / XSLT mit JavaScript bearbeiten:IE + Mozilla</title>
</head>
<body onload="init();">
<div>Books reviewed:
<a href="javascript:show('A Good Book')">A Good Book</a>
<a href="javascript:show('A Bad Book')">A Bad Book</a>
<a href="javascript:show('A So-so Book')">A So-so Book</a>
</div>
<div id="output" style="margin:1em"></div>
</body>
</html>