xml part 2
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 PresentationTRANSCRIPT
![Page 1: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/1.jpg)
XML Part 2
Josh SteeleCS 6704, Spring 2002
![Page 2: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/2.jpg)
XML Part 2
• XSL/XSLT– Structure Revisited – Definition– Example– Components
• XML’s Linking Languages• XML’s Uses
![Page 3: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/3.jpg)
Structure Revisited
Information Structure
Display
XML File
XSL File
XML Schema (.xsd) File
![Page 4: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/4.jpg)
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)
![Page 5: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/5.jpg)
XSLT
• Transforms one set of XML tags to another set of XML tags
• Benefits of this?
![Page 6: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/6.jpg)
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>
![Page 7: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/7.jpg)
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>
![Page 8: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/8.jpg)
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>
![Page 9: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/9.jpg)
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>………
![Page 10: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/10.jpg)
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>)
![Page 11: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/11.jpg)
Components (cont)
• Text– Literal text can be captured with the
<xsl:value-of> tag• Repetition
– Handled by use of the <xsl:for-each> tag
![Page 12: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/12.jpg)
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
![Page 13: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/13.jpg)
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>)
![Page 14: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/14.jpg)
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>
![Page 15: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/15.jpg)
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……
![Page 16: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/16.jpg)
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”/>
![Page 17: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/17.jpg)
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
![Page 18: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/18.jpg)
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)
![Page 19: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/19.jpg)
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”))
![Page 20: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/20.jpg)
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!
![Page 21: XML Part 2](https://reader035.vdocuments.us/reader035/viewer/2022062302/568167fc550346895ddd7766/html5/thumbnails/21.jpg)
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