XML als "XML-XHTML"
Mike
- xsl
Hi Leute
Ich habe ein XML, nun möchte ich es per XSLT als XHTML darstellen. Eigentlich nicht schwer, aber das besondere ich muss das XML 1zu1 abbilden, und das XSL, das ich brauche muss es mir so formatieren, dass ich es mit einem CSS, das ich auch bräuchte, da es ja vom XSL abhängig ist, als "XML-Code" darstellen kann.
kurz gesagt XML 1zu1 in einem Codefenster darstellen.
vielen dank im voraus
Hallo,
Ich habe ein XML, nun möchte ich es per XSLT als XHTML darstellen. Eigentlich nicht schwer, aber das besondere ich muss das XML 1zu1 abbilden, und das XSL, das ich brauche muss es mir so formatieren, dass ich es mit einem CSS, das ich auch bräuchte, da es ja vom XSL abhängig ist, als "XML-Code" darstellen kann.
kurz gesagt XML 1zu1 in einem Codefenster darstellen.
Du wendest dich vertrauensvoll an deinem IE.
Der stellt dir XML-Dokumente (onhe CSS oder XSLT) als XML-Baum dar:
---------------------------------------------------------------------
<HTML><HEAD>
<STYLE>BODY{font:x-small 'Verdana';margin-right:1.5em}
.c{cursor:hand}
.b{color:red;font-family:'Courier New';font-weight:bold;text-decoration:none}
.e{margin-left:1em;text-indent:-1em;margin-right:1em}
.k{margin-left:1em;text-indent:-1em;margin-right:1em}
.t{color:#990000}
.xt{color:#990099}
.ns{color:red}
.dt{color:green}
.m{color:blue}
.tx{font-weight:bold}
.db{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;border-left:1px solid #CCCCCC;font:small Courier}
.di{font:small Courier}
.d{color:blue}
.pi{color:blue}
.cb{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;font:small Courier;color:#888888}
.ci{font:small Courier;color:#888888}
PRE{margin:0px;display:inline}</STYLE>
<SCRIPT><!--
function f(e){
if (e.className=="ci"){if (e.children(0).innerText.indexOf("\n")>0) fix(e,"cb");}
if (e.className=="di"){if (e.children(0).innerText.indexOf("\n")>0) fix(e,"db");}
e.id="";
}
function fix(e,cl){
e.className=cl;
e.style.display="block";
j=e.parentElement.children(0);
j.className="c";
k=j.children(0);
k.style.visibility="visible";
k.href="#";
}
function ch(e){
mark=e.children(0).children(0);
if (mark.innerText=="+"){
mark.innerText="-";
for (var i=1;i<e.children.length;i++)
e.children(i).style.display="block";
}
else if (mark.innerText=="-"){
mark.innerText="+";
for (var i=1;i<e.children.length;i++)
e.children(i).style.display="none";
}}
function ch2(e){
mark=e.children(0).children(0);
contents=e.children(1);
if (mark.innerText=="+"){
mark.innerText="-";
if (contents.className=="db"||contents.className=="cb")
contents.style.display="block";
else contents.style.display="inline";
}
else if (mark.innerText=="-"){
mark.innerText="+";
contents.style.display="none";
}}
function cl(){
e=window.event.srcElement;
if (e.className!="c"){e=e.parentElement;if (e.className!="c"){return;}}
e=e.parentElement;
if (e.className=="e") ch(e);
if (e.className=="k") ch2(e);
}
function ex(){}
function h(){window.status=" ";}
document.onclick=cl;
--></SCRIPT>
</HEAD>
<BODY class="st"><DIV class="e">
<SPAN class="b"> </SPAN>
<SPAN class="m"><?</SPAN><SPAN class="pi">xml version="1.0" encoding="iso-8859-1" </SPAN><SPAN class="m">?></SPAN>
</DIV>
<DIV class="e">
<DIV class="c" STYLE="margin-left:1em;text-indent:-2em"><A href="#" onclick="return false" onfocus="h()" class="b">-</A>
<SPAN class="m"><</SPAN><SPAN class="t">data</SPAN><SPAN class="m">></SPAN></DIV>
<DIV><DIV class="e">
<DIV class="c" STYLE="margin-left:1em;text-indent:-2em"><A href="#" onclick="return false" onfocus="h()" class="b">-</A>
<SPAN class="m"><</SPAN><SPAN class="t">element</SPAN><SPAN class="t"> attribut</SPAN><SPAN class="m">="</SPAN><B>apfel</B><SPAN class="m">"</SPAN><SPAN class="m">></SPAN></DIV>
<DIV><DIV class="e">
<SPAN class="b"> </SPAN>
<SPAN class="tx">Text in einem Element </SPAN>
</DIV>
<DIV class="e"><DIV STYLE="margin-left:1em;text-indent:-2em">
<SPAN class="b"> </SPAN>
<SPAN class="m"><</SPAN><SPAN class="t">element</SPAN><SPAN class="t"> attribut</SPAN><SPAN class="m">="</SPAN><B>birne</B><SPAN class="m">"</SPAN><SPAN class="m">></SPAN><SPAN class="tx">Text: Birne</SPAN><SPAN class="m"></</SPAN><SPAN class="t">element</SPAN><SPAN class="m">></SPAN>
</DIV></DIV>
<DIV><SPAN class="b"> </SPAN>
<SPAN class="m"></</SPAN><SPAN class="t">element</SPAN><SPAN class="m">></SPAN></DIV>
</DIV></DIV>
<DIV class="e"><DIV STYLE="margin-left:1em;text-indent:-2em">
<SPAN class="b"> </SPAN>
<SPAN class="m"><</SPAN><SPAN class="t">element</SPAN>
<SPAN class="t"> attribut</SPAN><SPAN class="m">="</SPAN><B>birne</B><SPAN class="m">"</SPAN><SPAN class="m"> /></SPAN>
</DIV></DIV>
<DIV><SPAN class="b"> </SPAN>
<SPAN class="m"></</SPAN><SPAN class="t">data</SPAN><SPAN class="m">></SPAN></DIV>
</DIV></DIV>
</BODY>
</HTML>
----------------------------------------------------------------
Jetzt muss du nur noch für jeden Knotentpy im XML ein Template in XSL schreiben:
z.B. Elemente:
<xsl:template match="*">
<div class="e">
<span class="m"><</span><span class="t"><xsl:value-of select="name()" /></span>
<xsl:for-each select="@*">
<span class="t"><xsl:value-of select="concat(' ', name())" /></span>
<span class="m">="</span>
<b><xsl:value-of select="." /></b>
<span class="m">"</span>
</xsl:for-each>
<span class="m"> /></span>
<xsl:apply-templates />
<span class="m"></</span><span class="t"><xsl:value-of select="name()" /></span><span class="m">></span>
</div>
</xsl:template>
etc.
Aber es kann sein, dass so ein XSL bereits im Netz zu finden ist.
Grüße
Thomas