Upload
libba
View
51
Download
0
Embed Size (px)
DESCRIPTION
XML Part 2. Josh Steele CS 6704, Spring 2002. XML Part 2. XSL/XSLT Structure Revisited Definition Example Components XML’s Linking Languages XML’s Uses. Structure Revisited. Structure. Information. XML File. XML Schema (.xsd) File. Display. XSL File. XSL. - PowerPoint PPT Presentation
Citation preview
XML Part 2
Josh SteeleCS 6704, Spring 2002
XML Part 2
• XSL/XSLT– Structure Revisited – Definition– Example– Components
• XML’s Linking Languages• XML’s Uses
Structure Revisited
Information Structure
Display
XML File
XSL File
XML Schema (.xsd) File
XSL
• Stands for Extensible Stylesheet Language• Parts:
– XSLT – handles transformations– XPath – used to access or refer to parts of an XML
document– Formatting objects – XML Vocabulary for specifying
formatting semantics• Compatible with CSS2 (uses different syntax
though)
XSLT
• Transforms one set of XML tags to another set of XML tags
• Benefits of this?
Example - XML<?xml version=“1.0”?><?xml-stylesheet type=“text/xsl” href=“myxsl.xsl”?><Recipe xmlns:rec=“http://www.mysite.org/Recipe”xmlns:xsi=http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation=“myxsd.xsd” ><rec:Recipe cook = “XML Gourmet”>
<rec:Title>Bean Burrito</Title><rec:Category name = “tex-mex” /><rec:Ingredients>
<rec:Item>1 can refried beans</Item><rec:Item>1 cup longhorn colby cheese, shredded</Item>……
</rec:Ingredients><rec:Cooking Instructions>
Empty can of refried beans</rec:Cooking Instructions>
……</rec:Recipe>
XML Schema<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name=“recipe"> <xs:complexType> <xs:sequence> <xs:element name=“Title" type="xs:string"/> <xs:element name=“Category" type="xs:string"/> <xs:element name=“Ingredients" type="xs:string">
<xs:complexType> <xs:element name=“Item" minOccurs=“1" maxOccurs="unbounded“ type=“xs:string”/> </xs:complexType> </xs:element> <xs:element name=“CookingInstructions" type="xs:string"/> </xs:sequence></xs:complexType></xs:element>
</xs:schema>
Example - XSLT<xsl:stylesheet version = “1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform” xmlns=“http://www.w3.org/TR/xhtml1/strict”>
<xsl: outputmethod=“xml”encoding=“iso-8859-1” />
<xsl: template match = “Recipe”><html>
<head><title>
<xsl value-of select=“Recipe/Title” /></title>
</head><body>
<xsl:apply-templates /></body>
</html></xsl: template>
Example - XSLT (cont)<xsl:template match=“Recipe/Title”>
<h1><xsl:apply-templates />
</h1></xsl:template>
<xsl:template match=“Recipe/Ingredients”><h2>Ingredients</h2><ul>
<xsl:for-each select=“Item”><li>
<xsl:apply-templates /></li>
</xsl:for-each></ul>
</xsl:template>
<xsl:template match = “Recipe/CookingInstructions”><h2> Cooking Instructions </h2><p>
<xsl:apply-templates /></p>
</xsl:template>………
Components
• Template– Defines what should be changed, and how
• Pattern– Uses “match=“ attribute in template tag to point to a
specific element (uses XPath, more later)• Results
– Includes the HTML tags specified– <xsl: apply templates /> - applies template to the text
encapsulated by the tag (i.e. <CookingInstructions>)
Components (cont)
• Text– Literal text can be captured with the
<xsl:value-of> tag• Repetition
– Handled by use of the <xsl:for-each> tag
XML’s Linking Languages
• XLink– Alternative to XHTML for linking (the <a> tag) – <xmlns:xlink=http://www.w3.org/1999/xlink/namespace>
– <xlink:simple> – works just like <a> (with some more features)
– <xlink:extended>, <xlink:locator>, <xlink:arc > - provides a whole new set of linking policies
XLink: Simple
• Attributes:– href - resource you are linking to– role - string used to describe element’s role– title – optional title of link– show - opens the new resource in its own
window (new), embeds it in the current window (embed), or replaces the current window with the new one (replace)
– actuate – onRequest (click a link) or auto (like loading in <img>)
XLink:Extended
• Attributes:– Role, title – as in <xlink:simple>– showdefault – default value of show for all
locator elements– actuatedefault – default value of actuate for all
child elements– Needs helpers: <xlink:locator>, <xlink:arc>
XLink:LocatorThese <xlink:extended
role=“weapon list”title=“Description of Weapons”showdefault=“new”show actuate=“onRequest”>weapons
<xlink:locator title=“Longbow” href=“longbow.htm”/>
<xlink:locator title=“Crossbow” href=“crossbow.htm”/>
<xlink:extended> revolutionized medieval warefare……
XLink:arc
• Locators can be specified out-of-line– <xlink:locator href=“weaponlinkset.xml”/>– Allows different show and actuate parameters for
each locator• xlink:arc specifies those values in above file:
xlink:arcfrom=“sourcedoc”to=“longbowpic”show=“embed”actuate=“auto”/>
XPath
• Purposes:– To find and describe a section in the XML file
(used in XSLT)– To be able to point to a certain part of the
document (used in XPointers)• In essence makes a parse tree describing
the relationships between tags in the file
XPointers
• Allows one to point into a document (similar to anchors in HTML), but without any special notation (like id=“mytaghere”)
• Also allows selection of a section of the file (i.e. if you want section 25, it only downloads section 25, not the whole file)
XPointers (cont)
• 3 ways to reference:– #anchor (like in HTML)– #/1/3/4 (3rd tag under root, 4th tag under that)– #xptr (XPath expression)
• If you aren’t sure if there is an ID, you can concatenate different reference methods together
• Range: XPtr(id(“c2”) to id(“c3”))
XML Uses
• MathML – allows math expressions in web pages (www.w3.org/Math)
• XML-Data – provides mechanism to reference binary data within XML docs
• XHTML – a merging of XML and HTML• WIDL – Web Interface Definition
Language – allowed direct access to Web data from e-commerce or business apps
• And many more!
References
• XML for Dummies, 2nd edition (Ed Tittel, Frank Boumphrey)
• http://www.w3.org/TR/WD-xptr - XPointer• http://www.w3.org/TR/xslt - XSLT• http://www.w3.org/Style/XSL/ - XSL• http://www.w3.org/XML/ - XML