Presentation is loading. Please wait.

Presentation is loading. Please wait.

Attributes, Empty-Element Tags, and XSL

Similar presentations


Presentation on theme: "Attributes, Empty-Element Tags, and XSL"— Presentation transcript:

1 Attributes, Empty-Element Tags, and XSL
CH 5 Attributes, Empty-Element Tags, and XSL

2 Objective An attribute is a name-value pair included in an element’s start-tag Attributes typically hold meta-information about the element rather than the element’s data XSL is a powerful style language that enables you to transform documents from one XML vocabulary to other XML vocabularies or to non-XML vocabularies such as HTML or tab-delimited text

3 The Advantages of the XML Format
The data is self-describing The data can be manipulated with standard tools The data can be viewed with standard tools Different views of the same data are easy to create with style sheets

4 Attributes versus Elements
Attributes can’t hold structure well Attributes are unordered. Elements are ordered Elements allow you to include meta-metadata Elements are more extensible in the face of future changes Attributes are good places to put ID numbers, URLs, and references Other information not directly or immediately relevant to the reader

5 Attributes versus Elements cont…
Elements can have substructure; attributes can’t The attribute syntax is ambiguous Structural – Specifies relationship between the diff element in the document Semantic – related the individual elements to the real world Stylistic – Specifies how an element is diplay

6 A Simple XML Element Structure
Freely definable tags <article> <author>Gerhard Weikum</author> <title>The Web in Ten Years</title> <text> <abstract>In order to evolve...</abstract> <section number=“1” title=“Introduction”> The <index>Web</index> provides the universal... </section> </text> </article>

7 Attributes versus Elements cont…
<FACT SOURCE=”The Biographical History of Baseball, Donald Dewey and Nicholas Acocella (New York: Carroll & Graf Publishers, Inc. 1995) p. 169”> Josh Gibson is the only person in the history of baseball to hit a pitch out of Yankee Stadium. </FACT> VS <SOURCE> <AUTHOR>Donald Dewey</AUTHOR> <AUTHOR>Nicholas Acocella</AUTHOR> <BOOK> <TITLE>The Biographical History of Baseball</TITLE> <PAGES>169</PAGES> <YEAR>1995</YEAR> </BOOK> </SOURCE>

8 Multiple Attribute in XML
<ARTICLE DATE=”06/28/1969”DATE=”06/28/1969”> Polymerase Reactions in Organic Compounds </ARTICLE> This Above example is wrong because you can not have date attribute twice in one element

9 Multiple Elements in one XML
DATE children rather than attributes allows more than one date to be associated with an element <ARTICLE> <TITLE> Maximum Projectile Velocity in an Augmented Railgun </TITLE> <AUTHOR>Elliotte Harold</AUTHOR> <AUTHOR>Bruce Bukiet</AUTHOR> <AUTHOR>William Peter</AUTHOR> <DATE> <YEAR>1992</YEAR> <MONTH>10</MONTH> <DAY>29</DAY> </DATE> <YEAR>1993</YEAR> <DAY>26</DAY> </ARTICLE>

10 Good times to use attributes?
Attributes are fully appropriate for very simple data without substructure that the reader is unlikely to want to see Appropriate for simple information about the document that has nothing to do with the content of the document <SOURCE ID=”S1”> <AUTHOR ID=”A1”>Donald Dewey</AUTHOR> <AUTHOR ID=”A2”>Nicholas Acocella</AUTHOR> <BOOK ID=”B1”> <TITLE ID=”B2”> The Biographical History of Baseball </TITLE> <PAGES ID=”B3”>169</PAGES> <YEAR ID=”B4”>1995</YEAR> </BOOK> </SOURCE>

11 Empty Elements and Empty-Element Tags
An element that contains no content, not even white space, is called an empty element <STATION NETWORK=”CBS” CALL_LETTERS=”WCBS”CHANNEL=”2”></STATION>

12 XSL Transformations XSL - This is the Extensible Stylesheet Language
Divided into two parts 1. XSL Transformations (XSLT) 2. XSL Formatting Objects (XSL-FO)

13 XSL Transformations (XSLT)
XSLT enables you to replace one tag with another You define rules that map your XML tags to standard HTML tags XSLT can reorder elements in the document

14 XSL Formatting Objects (XSL-FO)
XSL-FO enables you to specify the appearance and layout of a page However, no web browsers yet support XSL formatting objects

15 The Transformation Process

16 XSLT Default Template An XSLT document contains one or more templates
The default templates are shown in the table below. Default Templates Node Type Default Template Root Apply templates for child nodes. Element Attribute Output attribute value. Text Output text value. Processing Instruction Do nothing. Comment

17 XML Sample <?xml version="1.0"?>
<?xml-stylesheet href="beatle.xsl" type="text/xsl"?> <person> <name> <firstname>Paul</firstname> <lastname>McCartney</lastname> </name> <job>Singer</job> <gender>Male</gender> </person>

18 XSLT Sample <?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl=" method="html"/> <xsl:template match="child::person"> <html> <head> <title> <xsl:value-of select="descendant::firstname" /> <xsl:text> </xsl:text> <xsl:value-of select="descendant::lastname" /> </title> </head> <body> </body> </html> </xsl:template> </xsl:stylesheet>

19 Code Explanation <xsl:stylesheet version="1.0" xmlns:xsl="

20 Code Explanation <xsl:value-of select="descendant::firstname" /> <xsl:text> </xsl:text> <xsl:value-of select="descendant::lastname" /> takes an XPath pointing to a specific element or group of elements within the XML document

21 XSLT Sample


Download ppt "Attributes, Empty-Element Tags, and XSL"

Similar presentations


Ads by Google