XML WITH CSS
Example1. xml <. xml version="1 Example1.xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml-stylesheet type="text/css" href="tutorials.css"?> <tutorials> <tutorial> <name>XML Tutorial</name> <url>http://www.quackit.com/xml/tutorial</url> </tutorial> <tutorial> <name>HTML Tutorial</name> <url>http://www.quackit.com/html/tutorial</url> </tutorial> </tutorials>
tutorials .css tutorials { margin:10px; background-color:#ccff00; font-family:verdana,helvetica, sans-serif; } name { display:block; font-weight:bold; } url { display:block; color:#636363; font-size:small; font-style:italic; }
XPath
XML documents can be thought of as a Tree Structure, made up of parent, child, and sibling relationships. XPath expression describes the location of an element or attribute in our XML document select any element in the document by creating a chain of children elements. XPath Expression inventory/snack/chips/amount XPath - @ is for Attribute! inventory/snack/chips@supplier
Absolute Location – from root Relative Location - to select every element amount XPath - Descendants "//“ drink//price XPath - Parent .. amount/.. XPath - Wildcard * inventory/snack/chips/* XPath – Combining Expressions with | inventory/snack/chips/* | inventory/drink/pop/* XPath – Predicates inventory/drink/lemonade[amount>15] inventory/*/*[@supplier='store'] inventory/drink/pop/amount[. < 20]
XPath Axes An axis defines a node-set relative to the current node axisname::nodetest[predicate] child::book Selects all book nodes that are children of the current node XPath Operators returns either a node-set, a string, a Boolean, or a number. Division 8 div 4 2 Equal price=9.80 TRUE/FALSE
XPath Standard Functions 100 built-in functions. Node-Set Functions position() String Functions string(e) Boolean Functions true() Number Functions round(e)
XSLT
Extensible Stylesheet Language Transformations XSL actually comes in two parts transformation language (XSLT) formatting language XSLT documents need to be well-formed and valid XML documents <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> </xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml-stylesheet type="text/xsl" href="tutorials.xsl"?> <tutorials> <tutorial> <name>XML Tutorial</name> <url>http://www.quackit.com/xml/tutorial</url> </tutorial> <name>HTML Tutorial</name> <url>http://www.quackit.com/html/tutorial</url> </tutorial> </tutorials>
XSLT <template> Element select a node from your XML document and transform its contents Selecting the Root Node <xsl:template match="/"> <xsl:template match="tutorials"> XSLT <apply-templates> Element determine where the content of its children appear
<xsl:template match="tutorials"> <html> <head> <title>My XSLT Example</title> </head> <body> <p>New content...</p> </body> </html> </xsl:template>
XSLT <value-of> Element retrieve the value from a node the select attribute to extract data from the child nodes <xsl:value-of select="name"/> the select attribute (“.”) specifies the current node <xsl:value-of select="."/> XSLT <for-each> Element loop through multiple nodes that match the selection criteria
XSLT <sort> Element sort the output of the <xsl:for-each> element. <xsl:sort select="name"/> XSLT <if> Element perform conditional statements against the contents of your XML document <xsl:if test=“@(attribute =‘value’ to check)"> the @ symbol - specify an attribute XSLT <choose> Element to compare a value against a range of possible values
used in conjunction with the <xsl:when> and <xsl:otherwise> elements <xsl:choose> <xsl:when test=“@(attribute=value)"> ---- </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose>
http://www.tizag.com/xmlTutorial/xslttemplate.php http://webdesign.about.com/gi/o.htm?zi=1/XJ&zTi=1&sdn=webdesign&cdn=compute&tm=536&f=00&tt=14&bt=0&bts=0&zu=http%3A//wdvl.internet.com/Software/XML/parsers.html