Before you read this tutorial, you should at least make sure that you are familiar with XML, edited XML, DTDs, and XSLT documents using Notepad or other tools, and are familiar with their syntax and purpose, otherwise you can read this tutorial after you have finished your class.
XML Spy is an editor developed by icon Information System that supports Xml,xsl,xslt,dtd,schema and many other file formats. It can show XML as a perfect tree structure, can easily use a variety of html/xml/xslt tags, use it can greatly save our development time, do not have to waste a lot of time on the input of the code. Let's learn how to use XML spy with an example of storing movie information.
The first step: we want to design three files: Saveit.xml,saveit.dtd and Saveit.xslt;saveit.xml are responsible for storing specific film content data, SAVEIT.DTD is responsible for saveit.xml validation, and SAVEIT.XSLT is responsible for SaveIt . xml transforms the style to determine its final display in the browser. Let's take a look at the code for the three files we need to build:
----------Saveit.xml------------------
<?xml version= "1.0" encoding= "GB2312"?
! DOCTYPE movies SYSTEM "G:\XMLSPY\SAVEIT.DTD" >
<?xml-stylesheet type= "text/xsl" href= "G:\xmlspy\saveit.xslt"?
<movies type= "action film"
<id> 1 </id>
<name> Fatal Cradle </name>
<brief> Jet Li's latest masterpiece! </brief>
<time> 2003 </time>
</movies>
----------SAVEIT.DTD------------------
<?xml version= "1.0" encoding= "GB2312"?
! ELEMENT Movies (ID, name, brief, time)
! attlist Movies Type CDATA #REQUIRED >
! ELEMENT ID (#PCDATA) >
! ELEMENT name (#PCDATA) >
! ELEMENT Brief (#PCDATA) >
! ELEMENT Time (#PCDATA) >
----------Saveit.xslt------------------
<?xml version= "1.0" encoding= "UTF-8"?
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform"
<xsl:output method= "xml" version= "1.0" encoding= "GB2312" indent= "yes"/>
<xsl:template match= "/" >
<title>
::: Lingyun's XML Spy tutorials:::
</title>
<body>
<xsl:apply-templates> </xsl:apply-templates>
</body>
</xsl:template>
<xsl:template match= "Movies"
Section <xsl:value-of select= "id" > </xsl:value-of> movie
<table>
<tbody>
<tr>
<td> name </td>
<td> Introduction </td>
<td> Time </td>
<td> type </td>
</tr>
<tr>
<td> <xsl:value-of select= "name" </xsl:value-of> </td>
<td> <xsl:value-of select= "brief" > </xsl:value-of> </td>
<td> <xsl:value-of select= "Time" </xsl:value-of> </td>
<td> <xsl:value-of select= "@type" > </xsl:value-of> </td>
</tr>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>