1 / 21

XML Part 2

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.

libba
Download Presentation

XML Part 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML Part 2 Josh Steele CS 6704, Spring 2002

  2. XML Part 2 • XSL/XSLT • Structure Revisited • Definition • Example • Components • XML’s Linking Languages • XML’s Uses

  3. Structure Revisited Structure Information XML File XML Schema (.xsd) File Display XSL File

  4. 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)

  5. XSLT • Transforms one set of XML tags to another set of XML tags • Benefits of this?

  6. 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-instance xsi: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>

  7. 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>

  8. 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: output method=“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>

  9. 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> ………

  10. 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>)

  11. Components (cont) • Text • Literal text can be captured with the <xsl:value-of> tag • Repetition • Handled by use of the <xsl:for-each> tag

  12. 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

  13. 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>)

  14. 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>

  15. XLink:Locator These <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……

  16. 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:arc from=“sourcedoc” to=“longbowpic” show=“embed” actuate=“auto”/>

  17. 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

  18. 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)

  19. 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”))

  20. 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!

  21. 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

More Related