Hallo!
Ich möchte XML-Dokumente in HTML umwandeln, in denen verschiedene Elemente mehrere optionale Attribute besitzen.
Das funktioniert prinzipiell, indem ich pro Element entsprechendes Inline-CSS erzeuge. Leider habe ich es noch nicht geschafft den Code in ein Attribut-Set o.ä. umzuwandeln, so dass er für jedes Element wiederholt wird. Auch wird zur Zeit nicht berücksichtigt, dass die Attribute optional sind. Der Browser muss die ungültigen CSS-Elemente entfernen.
Wie lässt sich der Code verbessern?
Vielen Dank von einem XSLT-Anfänger, Jens
mypage.xml :
mytranform.xsl
Ich möchte XML-Dokumente in HTML umwandeln, in denen verschiedene Elemente mehrere optionale Attribute besitzen.
Das funktioniert prinzipiell, indem ich pro Element entsprechendes Inline-CSS erzeuge. Leider habe ich es noch nicht geschafft den Code in ein Attribut-Set o.ä. umzuwandeln, so dass er für jedes Element wiederholt wird. Auch wird zur Zeit nicht berücksichtigt, dass die Attribute optional sind. Der Browser muss die ungültigen CSS-Elemente entfernen.
Wie lässt sich der Code verbessern?
Vielen Dank von einem XSLT-Anfänger, Jens
mypage.xml :
Code:
<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl" href="mytranform.xsl"?> <Page title="Test Title"> <FixedLabel row="1" col="1" text="Label 1" /> <FixedLabel row="2" col="1" text="Label2" foreColor="White" backColor="Blue" /> <DynamicLabel row="1" col="10" param="time" align="left" /> <DynamicLabel row="2" col="10" param="space" foreColor="White" backColor="Blue" /> </Page>
Code:
<?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="/Page"> <html> <head> <title> <xsl:value-of select="@title" /> </title> </head> <body> <div> <xsl:apply-templates/> </div> </body> </html> </xsl:template> <xsl:template match="FixedLabel"> <div class="label" style="top: {@row*11}pt; left: {@col*9}pt; color: {@foreColor}; background-color: {@backColor}"> <xsl:value-of select="@text" /> </div> </xsl:template> <xsl:template match="DynamicLabel"> <div class="parameter" style="top: {@row*11}pt; left: {@col*9}pt; width: {@len}em; text-align: {@align}; color: {@foreColor}; background-color: {@backColor}"> <span id="{@param}">---</span> </div> </xsl:template> </xsl:stylesheet>
Comment