My goal is to convert xml catalogs to html. The xml schema and the xml file is well formed and valid.
<?xml version="1.0" encoding="UTF-8"?> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="catalog"/> <xs:complexType name="textint"> <xs:sequence> <xs:element name="s" type="xs:string"/> <xs:element name="i" type="xs:int"/> <xs:element name="s" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType mixed="true" name="inttext"> <xs:sequence> <xs:element name="i" type="xs:int"/> <xs:element name="s" type="xs:string"/> <xs:element name="i" type="xs:int"/> <xs:element name="s" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:element name="Qstr"> <xs:complexType> <xs:sequence> <xs:element name="text" type="xs:string"/> <xs:element name="a" type="xs:string"/> <xs:element name="b" type="xs:string"/> <xs:element name="c" type="xs:string"/> <xs:element name="d" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Qfl"> <xs:complexType mixed="true"> <xs:sequence> <xs:element name="text" type="textint"/> <xs:element name="a" type="xs:int"/> <xs:element name="b" type="xs:decimal"/> <xs:element name="c" type="xs:int"/> <xs:element name="d" type="xs:int"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Qinttext"> <xs:complexType mixed="true"> <xs:sequence> <xs:element name="text" type="inttext"/> <xs:element name="a" type="xs:int"/> <xs:element name="b" type="xs:int"/> <xs:element name="c" type="xs:int"/> <xs:element name="d" type="xs:int"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Qtextint"> <xs:complexType mixed="true"> <xs:sequence> <xs:element name="text" type="xs:string"/> <xs:element name="a" type="textint"/> <xs:element name="b" type="xs:string"/> <xs:element name="c" type="xs:string"/> <xs:element name="d" type="textint"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> <?xml version="1.0" encoding="UTF-8"?> <Qstr> <text>Welcher Mechanismus kann unter Unix zur Kommunikation über das Netzwerk verwendet werden?</text> <a>Sockets</a> <b>Message Queues</b> <c>Pipes</c> <d>Semaphore</d> </Qstr> <Qstr> <text>Die Hauptstadt von Italien ist:</text> <a>Rom</a> <b>Athen</b> <c>Bonn</c> <d>Madrid</d> </Qstr> <Qfl> <text> <s>Die Quadratwurzel von </s> <i>100</i> <s> ist:</s></text> <a>10</a> <b>2.76</b> <c>5</c> <d>1</d> </Qfl> <Qinttext> <text> <i>1</i> <s>+</s> <i>1</i> <s>= ?</s> </text> <a>2</a> <b>1</b> <c>3</c> <d>4</d> </Qinttext> <Qtextint> <text>Spinnen...</text> <a> <s>...haben </s> <i>8</i> <s> Beine</s> </a> <b>...sind Insekten</b> <c>...sind Vögel</c> <d> <s>...werden bis zu </s> <i>100</i> <s> Jahre alt</s> </d> </Qtextint> <Qstr> <text>Die Hauptstadt von Spanien ist:</text> <a>Madrid</a> <b>Barcelona</b> <c>Rom</c> <d>London</d> </Qstr> Next I created an xsl stylesheet:
<xsl:template match="/"> <html> <head> <title>Simple Quiz</title> </head> <body> <xsl:for-each select="catalog/Qstr"> <table border="1"> <tr bgcolor="orange"> <th>Frage</th> </tr> <tr> <td><xsl:value-of select="catalog/Qstr/text"/></td> </tr> <tr bgcolor="orange"> <th>Antwortmöglichkeiten</th> </tr> <tr> <td><xsl:value-of select="catalog/Qstr/a"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qstr/b"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qstr/c"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qstr/d"/></td> </tr> </table> </xsl:for-each> <xsl:for-each select="catalog/Qfl"> <table border="1"> <tr bgcolor="orange"> <th>Frage</th> </tr> <tr> <td><xsl:value-of select="catalog/Qfl/text"/></td> </tr> <tr bgcolor="orange"> <th>Antwortmöglichkeiten</th> </tr> <tr> <td><xsl:value-of select="catalog/Qfl/a"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qfl/b"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qfl/c"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qfl/d"/></td> </tr> </table> </xsl:for-each> <xsl:for-each select="catalog/Qinttext"> <table border="1"> <tr bgcolor="orange"> <th>Frage</th> </tr> <tr> <td><xsl:value-of select="catalog/Qinttext/text"/></td> </tr> <tr bgcolor="orange"> <th>Antwortmöglichkeiten</th> </tr> <tr> <td><xsl:value-of select="catalog/Qinttext/a"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qinttext/b"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qinttext/c"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qinttext/d"/></td> </tr> </table> </xsl:for-each> <xsl:for-each select="catalog/Qtextint"> <table border="1"> <tr bgcolor="orange"> <th>Frage</th> </tr> <tr> <td><xsl:value-of select="catalog/Qtextint/text"/></td> </tr> <tr bgcolor="orange"> <th>Antwortmöglichkeiten</th> </tr> <tr> <td><xsl:value-of select="catalog/Qtextint/a"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qtextint/b"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qtextint/c"/></td> </tr> <tr> <td><xsl:value-of select="catalog/Qtextint/d"/></td> </tr> </table> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> As I am using ubuntu I chose oxygen for xml editing. The transformation was succesful, but the result not really.
I still don`t understand how xslt works. In oxygen I had 3 files opened: the xml schema, the xml file and the xslt file. Is that correct? What do I have to change in my xslt file in order to correctly display my whole xml catalog in html format?
No comments:
Post a Comment