Skip to content

Instantly share code, notes, and snippets.

@edames
Created July 22, 2012 03:57
Show Gist options
  • Save edames/3158319 to your computer and use it in GitHub Desktop.
Save edames/3158319 to your computer and use it in GitHub Desktop.
Extensible Markup Language
<table>
<tr>
<td>John <!-- Missing Closing Tag -->
<td>Smith</td>
<td>Lincoln, NE</td>
</tr>
</table>
<!-- Notice: XML, DTD, XML Schema, XSLT start with the XML version and encoding -->
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT employee (lastname, firstname, address, city, state, zipcode)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT zipcode (#PCDATA)>
<!--Comment describing your root element-->
<!ELEMENT employees ((employee))>
<employee>
<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
<address>123 West Avenue</address>
<city>Lincoln</city>
<state>Nebraska</state>
<zipcode>68588</zipcode>
</employee>
</employee>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="employeeType"/>
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element ref="firstname"/>
<xs:element ref="lastname"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="state"/>
<xs:element ref="zipcode"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="state" type="xs:string"/>
<xs:element name="zipcode" type="xs:string"/>
<xs:element name="employees">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="employeeType">
<xs:sequence>
<xs:element ref="employee"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2004/10/xpath-functions" xmlns:xdt="http://www.w3.org/2004/10/xpath-datatypes">
<xsl:output version="1.0" encoding="iso-8859-1" indent="no" omit-xml-declaration="yes" media-type="text/xml" />
<xsl:template match="/">
<html>
<head>
<title>Employee Example</title>
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0" width="776" bgcolor="#ffffff">
<tr valign="top">
<td><div style="margin: 5px 5px 5px 5px;">
<h3>Employees</h3>
<xsl:for-each select="employees">
<xsl:for-each select="employee">
Name: <xsl:for-each select="firstname">
<xsl:apply-templates />
</xsl:for-each>
&#160;<xsl:for-each select="lastname">
<xsl:apply-templates />
</xsl:for-each>
<br />Address: <xsl:for-each select="address">
<xsl:apply-templates />
</xsl:for-each>
<br />City: <xsl:for-each select="city">
<xsl:apply-templates />
</xsl:for-each>
<br />State: <xsl:for-each select="state">
<xsl:apply-templates />
</xsl:for-each>
<br />Zip Code: <xsl:for-each select="zipcode">
<xsl:apply-templates />
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</div></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<p></b>Employee</p></b> <!-- Improperly nested -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment