1 / 25

Extensible Markup Language II

Extensible Markup Language II. Namespace, XPath and XSL. XML Namespace. NamespaceS. XML Namespaces. Namespaces – provide method to avoid element name conflicts Collections of names identified by URIs

rasul
Download Presentation

Extensible Markup Language II

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. Extensible Markup Language II Namespace, XPath and XSL

  2. XML Namespace NamespaceS

  3. XML Namespaces • Namespaces – provide method to avoid element name conflicts • Collections of names identified by URIs • Namespaces allow names within a document to retain their original meanings even when combined with other document • However, if you don’t need namespaces, don’t use them

  4. Conflict examples <?xml version="1.0" encoding="ISO-8859-1"?><Order> <Customer> <Name>Johan Abdullah</Name> <Number>AE15562</Number> </Customer> <Items> <Item> <Name>Pioneer Hi-Fi</Name> <Number>PI-032-EX</Number> <Item> </Items> </Order>

  5. Namespaces Solution <?xml version="1.0" encoding="ISO-8859-1"?><Order xmlns:cus=“http://example.com/Customer” xmlns:item=“http://example.com/Item”> <cus:Customer> <cus:Name>Johan Abdullah</cus:Name> <cus:Number>AE15562</cus:Number> </cus:Customer> <item:Items> <item:Item> <item:Name>Pioneer Hi-Fi</item:Name> <item:Number>PI-032-EX</item:Number> </item:Item> </item:Items> </Order>

  6. Namespaces • Namespace declaration: • Defined by xmlns attribute xmlns:prefix = “URI” • Namespace URI is not used by parser to look for information

  7. <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body>  <h2>My CD Collection</h2>  <table border="1">    <tr>      <th align="left">Title</th>      <th align="left">Artist</th>    </tr>    <xsl:for-each select="catalog/cd">    <tr>      <td><xsl:value-of select="title"/></td>      <td><xsl:value-of select="artist"/></td>    </tr>    </xsl:for-each>  </table></body></html></xsl:template></xsl:stylesheet> Namespace for non-HTML tags (with xsl prefix, marked with red arrows)

  8. Navigating XML Document XPath

  9. XPath • Xpath – language to navigate and find information in XML document • Uses path expressions to navigate XML documents • Contains a library of standard functions

  10. Xpath Path Expressions/Functions • Xpath uses path expressions • Use path expressions to select nodes/node-sets in XML documents • Path expressions – similar to computer file system • Xpath includes more than 100 functions • Functions for string and numeric values, date/time comparison, node/QName manipulation, Boolean values etc.

  11. XPath Nodes - terminology • Seven kinds of nodes: • Element • Attribute • Text • Namespace • Processing-instruction (PI) • Comment • Document nodes • Atomic values – nodes without children or parent • Items – atomic values or nodes

  12. XPath Nodes - relationship • Types of relationship: • Parent • Children • Siblings • Ancestors • Descendants

  13. XPath Syntax • Selecting nodes

  14. XPath Syntax • Predicates – used to find a specific node/node with a specific value

  15. XPath Wildcards/| operator • Wildcards to select unknown XML elements • Use ‘|’ to select several paths

  16. More XPath References • XPath Axes - http://www.w3schools.com/xpath/xpath_axes.asp • XPath Operators - http://www.w3schools.com/xpath/xpath_operators.asp • XPath functions (with XQuery, XSLT) - http://www.w3schools.com/xpath/xpath_functions.asp

  17. XPath Example • Using Javascript – using “kereta.xml” • Edit the “ex1.html” , “ex2.html” and “ex3.html” files • Understand the usage of XPath and Javascript

  18. Extensible Stylesheet Language Transformation XSLT

  19. Displaying XML • XML documents don’t carry information about how to display data • 3 ways to display data: • XSLT (Extensible Stylesheet Transformation Language) • CSS (Cascading Style Sheet) • JavaScript

  20. XSL • XSL – Extensible Stylesheet Language • Style sheets for XML • Describes how the XML document should be displayed • Consisted of: • XSLT – transforming XML documents • XPath – navigating XML documents • XSL-FO – formatting XML documents

  21. XSL Transformation • XSLT – XSL Transformation • Transform XML documents to other formats (e.g. XHTML) – transform each XML element to XHTML element • Supported by all major browsers • Most important part of XSL • Allows adding/removing elements and attributes to/from output file, rearranging/sorting elements, perform test etc.

  22. XSLT - Transformation • Example of a transformation – steps: • Start with a raw XML document • Declare stylesheet • Create XSL style sheet • Link style sheet to the XML document

  23. <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">  <html>  <body>  <h2>My CD Collection</h2>  <table border="1">    <trbgcolor="#9acd32">      <th>Title</th>      <th>Artist</th>    </tr>    <xsl:for-each select="catalog/cd">    <tr>      <td><xsl:value-of select="title"/></td>      <td><xsl:value-of select="artist"/></td>    </tr>    </xsl:for-each>  </table>  </body>  </html></xsl:template></xsl:stylesheet> XSLT example

  24. XSLT Example • Using “kereta.xml” • Create/Edit the XSLT files to show various combination of sorting, filtering, formatting etc. • Understand the usage of XSLT

  25. The End – Thank You

More Related