Você está na página 1de 10

1. An XML Schema describes the structure of an XML document.

2. The purpose of an XML Schema is to define the legal building blocks of an XML
document, just like a DTD.
3. XML Schema is an XML-based alternative to DTD.
4. XML Schemas are much more powerful than DTDs.
5. The XML Schema language is also referred to as XML Schema Definition (XSD).
XML Schema Example
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>

An XML Schema:

It defines elements that can appear in a document

It defines attributes that can appear in a document
It defines which elements are child elements
It defines the order of child elements
It defines the number of child elements
It defines whether an element is empty or can include text
It defines data types for elements and attributes
It defines default and fixed values for elements and attributes


<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="4364"
<name>SMIT College</name>
<address>Muthu Nagar</address>
<title>JSP Begins</title>
<note>Special Edition</note>
<title>Web Technology</title>
The XML document above consists of a root element, "shiporder", that contains a required
attribute called "orderid". The "shiporder" element contains three different child elements:
"orderperson", "shipto" and "item". The "item" element appears twice, and it contains a "title", an
optional "note" element, a "quantity", and a "price" element.
The line above: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" tells the XML
parser that this document should be validated against a schema. The line: xsi: noNamespace
SchemaLocation="shiporder.xsd" specifies WHERE the schema resides (here it is in the same
folder as "shiporder.xml").


<?xml version="1.0" encoding="UTF-8" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of simple elements -->
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
<!-- definition of attributes -->
<xs:attribute name="orderid" type="xs:string"/>
<!-- definition of complex elements -->
<xs:element name="shipto">
<xs:element ref="name"/>
<xs:element ref="address"/>
<xs:element ref="city"/>
<xs:element ref="country"/>

<xs:element name="item">

<xs:element ref="title"/>
<xs:element ref="note" minOccurs="0"/>
<xs:element ref="quantity"/>
<xs:element ref="price"/>
<xs:element name="shiporder">
<xs:element ref="orderperson"/>
<xs:element ref="shipto"/>
<xs:element ref="item" maxOccurs="unbounded"/>
<xs:attribute ref="orderid" use="required"/>



XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML
XSLT stands for XSL Transformations.XSLT to transform XML documents into other
formats, like XHTML.

The <xsl:template> Element
A template contains rules to apply when a specified node is matched
The <xsl:value-of> Element
Extract the value of a selected node
The <xsl:for-each> Element
Select every XML element of a specified node-set with the <xsl:for-each> element
The <xsl:sort> Element
Sort the output in a node-set
The <xsl:if> Element
Put a conditional test against the content of an XML file
The <xsl:choose> Element
This example will add a pink background-color to the "Name" column WHEN the price of the
CLASS is higher than 10:
The <xsl:apply-templates> Element
Apply templates to elements

Source :
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Transfer.xsl"?>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h2>Student Database</h2>
<table border="2">
<tr bgcolor="#9acd32">
<th style="text-align:left">Student Name</th>
<th style="text-align:left">Dept.</th>
<xsl:for-each select="student/class">
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="dept"/></td>