Created
May 10, 2012 12:36
-
-
Save mhubig/2652789 to your computer and use it in GitHub Desktop.
XML-Example with a matching XML-Schema-Definition and a simple XSLT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <sendeliste xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:noNamespaceSchemaLocation="https://raw.github.com/gist/2652789/sendeliste.xsd"> | |
| <beitrag> | |
| <title>Baby One More Time</title> | |
| <interpret>Britney Spears</interpret> | |
| <dauer minuten="2" sekunden="30" /> | |
| <produktionsjahr>1999</produktionsjahr> | |
| <sendedatum>2012-03-03 20:32:10</sendedatum> | |
| </beitrag> | |
| <beitrag> | |
| <title>Baby One More Time (Timothy Bold Remix)</title> | |
| <interpret>Britney Spears</interpret> | |
| <dauer minuten="6" sekunden="30" /> | |
| <produktionsjahr>2012</produktionsjahr> | |
| <sendedatum>2011-04-03 19:12:10</sendedatum> | |
| </beitrag> | |
| </sendeliste> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
| <!-- definition of simple elements --> | |
| <xs:element name="title" type="xs:string"/> | |
| <xs:element name="interpret" type="xs:string"/> | |
| <xs:element name="produktionsjahr" type="xs:positiveInteger"/> | |
| <xs:element name="sendedatum" type="xs:date"/> | |
| <!-- definition of attributes --> | |
| <xs:attribute name="minuten" type="xs:positiveInteger"/> | |
| <xs:attribute name="sekunden" type="xs:positiveInteger"/> | |
| <!-- definition of complex elements --> | |
| <xs:element name="dauer"> | |
| <xs:complexType> | |
| <xs:attribute ref="minuten" use="required"/> | |
| <xs:attribute ref="sekunden" use="required"/> | |
| </xs:complexType> | |
| </xs:element> | |
| <xs:element name="beitrag"> | |
| <xs:complexType> | |
| <xs:sequence> | |
| <xs:element ref="title"/> | |
| <xs:element ref="interpret"/> | |
| <xs:element ref="dauer"/> | |
| <xs:element ref="produktionsjahr"/> | |
| <xs:element ref="sendedatum"/> | |
| </xs:sequence> | |
| </xs:complexType> | |
| </xs:element> | |
| <xs:element name="sendeliste"> | |
| <xs:complexType> | |
| <xs:sequence> | |
| <xs:element ref="dhbw:beitrag" maxOccurs="unbounded"/> | |
| </xs:sequence> | |
| </xs:complexType> | |
| </xs:element> | |
| </xs:schema> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <xsl:stylesheet version="1.0" | |
| xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
| xmlns="http://www.w3.org/1999/xhtml"> | |
| <xsl:template match="sendeliste"> | |
| <html> | |
| <body> | |
| <table border="1"> | |
| <tr bgcolor="#9acd32"> | |
| <td> Title </td> | |
| <td> Interpret </td> | |
| <td> Dauer </td> | |
| <td> Produktionsjahr </td> | |
| <td> Sendedatum </td> | |
| </tr> | |
| <xsl:apply-templates select="beitrag"> | |
| <xsl:sort select="sendedatum" order="ascending" /> | |
| </xsl:apply-templates> | |
| </table> | |
| <hr /> | |
| <table border="1"> | |
| <tr bgcolor="#9acd32"> | |
| <td> Title </td> | |
| <td> Interpret </td> | |
| <td> Dauer </td> | |
| <td> Produktionsjahr </td> | |
| <td> Sendedatum </td> | |
| </tr> | |
| <xsl:apply-templates select="beitrag"> | |
| <xsl:sort select="produktionsjahr" order="ascending" /> | |
| </xsl:apply-templates> | |
| </table> | |
| </body> | |
| </html> | |
| </xsl:template> | |
| <xsl:template match="beitrag"> | |
| <tr> | |
| <td> | |
| <xsl:value-of select="title" /> | |
| </td> | |
| <td> | |
| <xsl:value-of select="interpret" /> | |
| </td> | |
| <td> | |
| <xsl:value-of select="dauer/@minuten" /> Minuten und | |
| <xsl:value-of select="dauer/@sekunden" /> Sekunden | |
| </td> | |
| <td> | |
| <xsl:value-of select="produktionsjahr" /> | |
| </td> | |
| <td> | |
| <xsl:value-of select="sendedatum" /> | |
| </td> | |
| </tr> | |
| </xsl:template> | |
| </xsl:stylesheet> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Die XSLT Datei kann hier ausprobiert werden.