Welcome

To my corner on the net... Warning, this is a techie blog! Non-techie people may suffer bouts of epilepsy on viewing this blog. The author cannot be held responsible.

XML Part 7

Wednesday, 30 November 2011

Discuss how XSL can be used to generate XHTML, with examples


XSL (Extensible Style Sheet Language) which was designed specifically for XML defines and the transformation and presentation rules of an XML document. Although it is quite similar to CSS, XSL is superior in manipulating the structure in XML documents. 

XSLT, XSL-FO and XPATH all make part of XSL. XSLT is the only components that is supported by modern browsers and allows the transformation of XML documents using style sheet code from language to another. 

XSL-FO stands for “Extensible Style sheet Language Formatting Objects” and is primarily a W3C recommendation language for formatting XML data. W3C states that XSL-FO is now formally named XSL. This language is also suitable for formatting XML documents, not only for the screen but also for printing. Notably XSL-FO is also suitable for converting  XML documents into a Adobe PDFs (Portable Document Format).

XPath, which is a major element of XSLT is and a W3C recommendation, is an expression language that is used to navigate through parts of an XML document. It basically encompasses syntax that can be used to define parts of an XML document and includes path expressions that are used to navigate through an XML document. 

HTML (Hyper Text Markup Language) is not a XML based language therefore does not meet the standards of XML. It is widely used today in web design.  To adhere to XML standards, another version of HTML was introduced called XHTML.  To work effectively with XML data one must have a means to transform the data into XHTML which is after all the outcome that the browser will parse through and interpret. This transformation can be done through XSLT. 

The example below shows how an XSL stylesheet is created for an XML document.


The XML Document :
<?xml version="1.0" encoding="ISO-8859-1"?>
<library>
                <book>
                                <title>Cloud Computing a practical approach</title>
                                <author>Author 1</author>
                                <country>USA</country>
                </book>
                <book>
                                <title>Cloud Computing Data Center</title>
                                <author>Author 2</author>
                                <country>UK</country>
                </book>
                <book>
                                <title>Cloud Computing for dummies</title>
                                <author>Author 3</author>
                                <country>CANADA</country>
                </book>
</library>

And here is the XSLT Stylesheet :

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My Cloud Computing Library</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Author</th>
        <th>Country</th>
      </tr>
      <xsl:for-each select="library/book">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="author"/></td>
        <td><xsl:value-of select="country"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

In fact, at the example above shows, XSLT is more than just styling in the sense that we usually consider styling for CSS. XSLT is actually building the content from the XML data. It even includes looping through the XML elements which is something which cannot be done through CSS.

How can XML be styled using CSS?  What are the strengths and weaknesses of using CSS?  Give example to illustrate your answers.



CSS which is widely used in web design to style HTML can also be used to style XML although it is not the preferred way to style. The advantage of CSS over XSLT is its wide acceptance and compatibility with popular browsers. CSS does however had an inherent weakness in that it can be used only to display and style the content and lacks that control features such as looping that are standard in XSLT. CSS does not transform and process the XML data but simply lists it with the style and positioning outlined in the CSS stylesheet.

The CSS styling rules are usually contained in textfiles that have the .css file extension and are stored separately. The CSS file to be used has to be referenced in the XML document just like is done in web design when using CSS with HTML.

The example below shows how XML can be styled using CSS.

The XML file :

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="css.css"?>

    <library>
                    <book>
                                    <title>Cloud Computing a practical approach</title>
                                    <author>Author 1</author>
                                    <country>USA</country>
                    </book>
                    <book>
                                    <title>Cloud Computing Data Center</title>
                                    <author>Author 2</author>
                                    <country>UK</country>
                    </book>
                    <book>
                                    <title>Cloud Computing for dummies</title>
                                    <author>Author 3</author>
                                    <country>CANADA</country>
                    </book>
    </library>

The CSS Stylesheet :

library
{
background-color: #ffffff;
width: 500px;;
border: 1px solid black;
}
book
{
display: block;
margin-left: 0;
border-top: 1px solid gray;
background-color: #eee;
padding: 10px;
}
title
{
color: #FF0000;
font-size: 20pt;
}
author
{
color: #0000FF;
font-size: 20pt;
}

And finally the output:


















The strengths of CSS
CSS is a very powerful sytling language which is in widespread use today and is supported by most browsers. CSS code is inherently simple to follow and understand and the learning curve is shallow. Perhaps CSS’s biggest advantage is the ability to allow the same code to be used repeatedly throughout a web project. Besides shortening the code considerably, this technique also allows for homogeneity throughout the project.

The Weaknesses of CSS
CSS is primarily weak in the support of printing of documents that are styled with it. This is because of the way how CSS deals with positioning and how it is aimed at mainly positioning things on the screen and not on paper. CSS also lacks any support for mathematical calculations so without the use of other languages such as PHP CSS would have to be taken “as-is” and would only be modifiable through actually typing in the changes and not on the fly.
Another weakness is the ease with which CSS can be overridden by hackers and how this would affect the output of the data being displayed without the developer having any control over the changes.



How can XML be styled using XSLT style sheets?  What are the strengths and weaknesses of using XSLT style sheets?  Give example to illustrate your answers.


Styling involves the transforming and formatting of the information to produce a readable result that contains the styling rules that the author designed. W3C has two recommendations to make styling of XML possible, namely XSL Transformations or XSLT and XSL. XSLT allows for the reorganization of information while XSL specifies formatting details which are then used in rendering. Using XSL and XSLT together does not only produced a styled document but also a result tree that can be expanded, modified, and rearranged.

The example below shows the transformation of an XML file into styled output :

The XML File :

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
    <library>
                    <book>
                                    <title>Cloud Computing a practical approach</title>
                                    <author>Author 1</author>
                                    <country>USA</country>
                    </book>
                    <book>
                                    <title>Cloud Computing Data Center</title>
                                    <author>Author 2</author>
                                    <country>UK</country>
                    </book>
                    <book>
                                    <title>Cloud Computing for dummies</title>
                                    <author>Author 3</author>
                                    <country>CANADA</country>
                    </book>
    </library>

Note that in the XML file above, the second line is referencing a style sheet called test.xsl. This is similar to the way that CSS stylesheets can be referenced inside an XML document.

The listing below is for the XSLT file that is going to transform and style the XML above :

<?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>
  <h1>My Cloud computing Books</h1>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Title</th>
      <th>Author</th>
                  <th>Country</th>
    </tr>
    <xsl:for-each select="library/book">
    <tr>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="author"/></td>
                  <td><xsl:value-of select="country"/></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

It is important to note in the example above the use of the “for-each” loop which is transforming the data by reading through the XML tree. This is something that is not possible with other styling languages like CSS for example.  The “<xsl:template match="/">” line is included to indicate that the transformation should start at the root node of the XML document. The fact that XSLT not only styles but also transforms the document is perhaps its most notable advantage, however, it does lack the ability for full styling and a combination of XSLT and CSS would have to be used to avoid using deprecated HTML tags.

Finally the output will look like this :


To style the green header the XSLT code is using deprecated styling techniques and for this reason CSS can be used to style the tables in this example. This would involve including a CSS declaration in the XSLT stylesheet so that the browser will know where to get the CSS code from.

The stylesheet now look like :

<?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>
               <head><link rel="stylesheet" type="text/css" href="css1.css"/></head>
  <body>
  <h1>My Cloud computing Books</h1>
  <table border="1">
    <tr class="green">
      <th>Title</th>
      <th>Author</th>
                  <th>Country</th>
    </tr>
    <xsl:for-each select="library/book">
    <tr>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="author"/></td>
                  <td><xsl:value-of select="country"/></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

Note that the “bgcolor” has now been replaced with a CSS class. And finally here is the CSS code being used in “css1.css” file :

.green {
background-color: #9acd32;
}




How can XSLT be used (a) to transform an XML structure and (b) to sort the contents of an XML document?

XSLT or “eXtensible Markup Language Transformation” is used to transform XML documents into HTML based document which is ultimately what all browsers expect,  and understand. Once a document is converted to HTML CSS can be used to style it as well as at the same time using XSLT to transform it. Please look at the last paragraphs in the previous entry of this post for an example. It is important to consider that XML is incomprehensible to the browser as-is and must first be transformed to be rendered correctly. This is done through XSLT. Further styling in terms of graphical style and colouring is then done through CSS by incorporating external (or internal) CSS stylesheets. 
XSLT allows the developer to perform transformations and processing of the XML data file. Loops are for example supported which will iterate through the XML data and display the contents as specified by the code of the XSLT file. At the same time, XPATH, one of the components of XSLT, is used to create logical paths in the XML document during processing. XPATH effectively assists XSLT to define source documents, which match against templates that are predefined. Transformation will occur when there is matching documents between the defined source document and a template.

In XSLT the <xsl:sort> is used to sort the data in an XML file and return sorted output. The following code snippet shows the code being applied in practice. This is taken from an example at W3C.

      <xsl:for-each select="catalog/cd">
      <xsl:sort select="artist"/>
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>


Discuss the notion of Xlink.  What  is its purpose and how do you use it? Give example to illustrate your answers.

XLink is primarily a W3C recommendation XML Linking Language that is used for creating hyperlinks in an XML document in a similar way as they are created in traditional HTML documents. Xlink, however offers several advantages in creating hyperlinks over HTML. Typically, any element in an XML document can be used as and behaves as an XLink element. Xlink also supports using extended links which are used to link multiple documents together. As Xlink can treat any element as if it were a hyperlink, the linked files themselves need not contain the link which adds great flexibility.

The example below taken from a W3C tutorial shows XLink in action in a typical XML file. The second line is declaring the XLink Namespace which means that it is going to be needed to render this document. The “  xlink:type="simple"” is specifying that a simple link like those used in HTML is required. As stated previously, “multidirectional” links are also supported.
The    syntax of xlink:href=http://book.com/images/HPotter.gif xlink:show="new"> includes the link where the URL is located and also if it is to open in a new browser window, again, similar to HTML.

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">

<book title="Harry Potter">
  <description
  xlink:type="simple"
  xlink:href="http://book.com/images/HPotter.gif"
  xlink:show="new">
  As his fifth year at Hogwarts School of Witchcraft and
  Wizardry approaches, 15-year-old Harry Potter is.......
  </description>
</book>
</bookstore>

XML Part 6

Tuesday, 22 November 2011

Discuss the roles of entities in XML, giving examples what problems can occur when they are not used properly. 


In XML Entities are declarations that are intended to specify references to values. Entities are advantageous because they are used to replace frequently typed (or included) text. Usually and entity is defined to contain text and during rendering this text is replaced as specified thus ensuring that the same text appears and also making the data shorter. The parser will also check that the entity names are spelled correctly as specified.

Entities may be :

  • Replacement text or parsed
  • Un-parsed which may be or may not be replacement text
  • General entities which are only used in the context of the document itself
  • Parameter entities which are parsed entities used within the DTD.


Entity declarations can also be used by more than one XML file, thus further adding to the advantages outlined above.  Using entities encourages the re-use of text and is often used in defining standardized warning messages and also in applications that require language and locale customizations. When this paradigm is implemented on a large scale some sort of “Entity Management System” would need to be employed to keep things clear. XML itself does not include such a system and it would have to be added on.

Entity references are applied in XML documents by using a special character “the ampersand” or “&” followed by a semicolon (;). Entities must have unique names and when using external entities, the SYSTEM keyword is used to identify and locate a file.

Optionally the “PUBLIC” keyword is used in addition to the SYSTEM keyword. Below is an example of an entity called ‘whc’ referring to the internal value ‘WebHomeCover.com’ and external entity reference in XML document:


<!ENTITY bgc  “borggardencenter.com”>

<companyName>&bgc;</companyName>

One of the problems with XML is that it already uses a number of characters from the standard character set in its syntax such as “<” and “>” and the ampersand symbol itself. These are used in defining the XML itself and the parser will of course interpret them as part of it. To use these special characters as part of the data an entity is used.  HTML web developers are very aware of the pre-defined entities in HTML that cover for commonly used symbols such as :


        &lt;     Left angle bracket (<)

        &gt;     Right angle bracket (>)

        &apos;   Single quote character (')

        &quot;   Double quote character (")

        &amp;    Ampersand (&)




Many times characters that are not accessible through the keyboard need to be included in documents. These special cases are special cases of entity references which refer to characters in the UNICODE reference.  


These special references can either be made through a decimal notation such as &#2513 or as in hexadecimal notation such as &#413E.  


As already mentioned, external entities also help in reducing the size of documents and also in separating the document into logical divisions which are stored as separate external entities. This makes the data more manageable and easier to handle. This feature thus provides a mechanism that is used to creat re-usable components that can be used across multiple documents.


External Binary data such as that which is used to render images can also be included as an external entity reference.  The NDATA keyword is used to denote such data and to instruct the parser to render them as whatever they are intended to be. NDATA stands for Non-Parsable Data which indicates that it should not be handled by the parse as standard textual data. Example :


<!ENTITY logo SYSTEM “mylogo.gif” NDATA  gif>

Entities also aid the construction of a DTD and as many as required can be specified in a DTD.

Example with an internal DTD


 <?xml version="1.0" standalone="yes" ?>

<!DOCTYPE publisher [

  <!ELEMENT publisher (#PCDATA)>

  <!ENTITY hc "Harper Collins">

  <!ENTITY mp “Macmillan Publishers”>

  <!ENTITY yp “Yale Publishers”>

]>

Corresponding XML :

<publisher>&hc;</ publisher >

< publisher >&mp;</ publisher >

< publisher >&yp;</ publisher >



Example of referencing External entity files :

  <?xml version="1.0" ?>

<!DOCTYPE publisher [



  <!ELEMENT publisher (#PCDATA)>

  <!ENTITY hc SYSTEM "data1.xml">

  <!ENTITY mp SYSTEM “data2.xml”>

  <!ENTITY yp SYSTEM “data3.xml”>

]>



< publisher >&hc;</ publisher >

< publisher >&mp;</ publisher >

< publisher >&yp;</ publisher >


 
 
Review the correct use of character sets in XML, discussing the advantages and disadvantages of different sets, with examples.  How would you select your character sets to present Chinese characters?




In XML character sets specify which characters are permitted in the XML document and are mainly two types, “broad” or  “restrictive”. Restrictive character sets, for example, would typically be used to restrict the text in a document to upper case. On the other hand a “broad” character set would be used to include many characters such as Arabic notation and other non-roman character notations.



ASCII

The most well known and widely used character set is ASCII where each character is represented by a “character encoding value”. In ASCII the character code value for an capital "A" would be 65, and for “B” it would we 66 and so on. ASCII is based on a 7-bit encoding scheme which means that only 128 different values are possible and hence 128 characters. ANSI extends this limitation by using 8 bits instead of 7 and therefore providing for 256 different characters. ASCII does not support languages that contain non-European alphabets such as Cryllic and Arabic which is perhaps its biggest limitation. It also does not support a great deal of symbols such as mathematical and technical symbols. On the other hand ASCII does have its advantages and it’s widespread use is probably its biggest advantage together with the fact that many documents that are already in electronic archives are written in ASCII. Its lack of proper symbols for technical works makes it unsuitable but it does include the basic arithmetic symbols which are enough for most non-technical documents.


Unicode

Unicode is the solution to the problems experiences with ASCII, namely the limited number of characters that are included. Unicode is the preferred character set for XML and includes enough characters to cover the world’s languages and alphabets. The two most widely used encoding schemes for Unicode are UTF-8, and UTF-16. UTF-8 uses 8 bits, and is compatible with 7-bit ASCII. UTF-8 is able to represent other characters using two or more byte combinations.


Unicode covers over 107, 000 characters in over than 90 scripts. These include European, Asian, American, African and even some languages which are no longer spoken.

Unicode was designed to be compatible with the widely used ASCII and the first 256 characters are identical to ISO-8859-1 of which 128 characters are the same as in ASCII. This compatibility ensures easy conversion of documents from ASCII to Unicode.

Unicode also has full support for a very large number of mathematical, technical, scientific, cultural and artistic expressions.


The main disadvantage with Unicode if it can be classified as a disadvantage is mainly its late adoption. It cannot be used in Database object names such as field names, for example.

UTF-8 encoding supports both simplified and traditional Chinese text.  Special “meta” tags are used in the document to specify that UTF-8 encoding is going to be used such as :


<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>



It is also possible to use GB encoding to display Chinese characters although this is mostly used to display simplified Chinese characters. In this case the “meta” tag would be :


<meta http-equiv="Content-Type" content="text/html; charset=gb18030"/>


Finally Chinese text may also be displayed using “Big5” encoding but this is usually used for Traditional Chinese. In this case the “meta” tag would be : 


<meta http-equiv="Content-Type" content="text/html; charset=big5"/>







Describe and discuss the logical modelling of data in the context of XML.


The Logical Data Model (LDM) in XML deals with the actual implementation of a conceptual module in a database and represents the normalized design of the common data model in information systems. The LDM refers to the representation of the data in a particular organization and to managing the enterprise data in the information systems of that organisation.

There are many several of the LDM, namely, the relational model, the object oriented model and the Extensible Markup Language (XML) model. The relational model defines the data model in terms of traditional rows and columns and allows for the definition of relationships between tables. The object oriented model defines data in terms of classes and objects which have attributes and associations. Finally, the XML model represents data in terms of tags, attributes and elements and is quickly becoming the selected way to build components information systems.

Using XML it is possible to model information system in natural and intuitive ways. This paradigm attempts to ensure that time and effort is spent on doing what is needed to be done rather than concentrate on how to do it.

XML supports “Heterogeneitywhere each "record" can include different data fields which is a considerable advantage as in a real scenario data is not organized into tables, rows, and columns. This allows the data to be displayed as it is in the real world and does away with many of the restrictions attributed to traditional database systems. Coupled with this, the XML data model also supports Extensibility where new types of data can be added at will and don't need to be thought out beforehand. Again, this is an advantage over traditional systems.

The advantage of using XML’s Logical Data Model is that the model is inherently self-describing which means that applications can be made to automatically re-build themselves according to the data. XML can be considered as a universal information structuring which in itself contains the information to build the data structures, thus doing away with separate database design mechanisms.

In order to effectively model information using XML natural pattern identification has to be made.





What is the role of namespaces in XML?  What benefits does the use of namespaces confer and what problems may be avoided? 
 


In XML, from one master schema document, Namespaces are used to include references to other schemas as required by the application. This encourages and allows the use of several schemas within an XML document.
Namespaces are collections of names of elements, element types, and attributes in a schema. This paradigm presents the possibility that collisions may occur because, for example, an element in one schema may have the same name as an element in another scheme resulting in a conflict. When one considers that there may be many elements in different schemas the possibility of this occurring is a real danger. For this reason Namespaces are also referred to as “vocabularies” as the contain a collection of names and definitions just like a traditional vocabulary.

With namespaces, prefixes may be added to associate names with schemas and thus making them unique. This will enable elements, types, and attributes to be referenced from a particular schema precisely and without room for confusion. Names from XML schema documents usually employ the “xs:” or “xsd:” prefix. 

The example below shows how components from other bookstore schemas can be included in the XML document by first identifying the namespaces and defining prefixes for those namespaces in the schema element of the schema document :

<xml version=”1.0” encoding=”UTF-8”?>
<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
targetNamespace=”http://xmlfd.com/ns/bookstore”
xmlns:ob=”http://www.oregonbooksellers.com/oregonBooks”
xmlns:nwb=”http://www.northwestbooks.net/new”
xmlns:fic=”http://www.fictionwriters.org/fiction”
elementFormDefault=”qualified”>
Source : XML for Dummies by Wiley Publishing

The xsd:import elements are then added to indicate where the schema documents for
these namespaces can be found, as shown below :

<xsd:import namespace=”http://www.oregonbooksellers.com/oregonBooks”
schemaLocation=”books.xsd”/>
<xsd:import namespace=”http://www.northwestbooks.net/new”
schemaLocation=”newbooks.xsd”>
<xsd:import namespace=”http://www.fictionwriters.org/fiction”
schemaLocation=”fiction.xsd”>
<xsd:element name=”books”>
Source : XML for Dummies by Wiley Publishing

The first line of the schema element declares the default namespace for the schema or the XML Schema namespace  and associates the xsd: prefix with this namespace so that names such as schema, element, attribute, as defined by the XML Schema specification can be used:

xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”

Secondly on the second line namespace is being created for the elements defined in this schema document. By specifying a target namespace we are allowing the use these components in other schema documents as follows :

targetNamespace=”http://xmlfd.com/ns/bookstore”

The next three lines in the schema element associate prefixes with additional namespaces, so they can be used as components from those schemas in the schema document:

xmlns:ob=”http://www.oregonbooksellers.com/books.xsd”
xmlns:nwb=”http://www.northwestbooks.net/newbooks.xsd”
xmlns:fic=”http://www.fictionwriters.org/fiction.xsd”>

By default only Global Elements which are children of the schema element are associated with the target namespace.Local elements may be added to the target namespace as follows :

elementFormDefault=”qualified”

Finally, the next three lines in the schema document point to the location of the external schemas associated with the three imported namespaces:

<xsd:import namespace=”http://www.oregonbooksellers.com/books.xsd”
schemaLocation=”books.xsd”/>
<xsd:import namespace=”http://www.northwestbooks.net/newbooks.xsd”
schemaLocation=”newbooks.xsd”>
<xsd:import namespace=”http://www.fictionwriters.org/fiction.xsd”
schemaLocation=”fiction.xsd”>

The prefix is the included to access elements from the other namespaces as follows 

<xsd:element name=”book”>
<xsd:complexType>
<xsd:sequence maxOccurs=”unbounded”>
<xsd:element ref=”author”/>
<xsd:element ref=”ob:title”/>
<xsd:element ref=”nwb:publisher”/>
<xsd:element ref=”fic:price”/>
<!–xsd:sequence>
<!–xsd:complexType>
<!–xsd:element>
<xsd:element name=”author” type=”xsd:string”/>

Examples are sourced from : XML for Dummies by Wiley Publishing



What is Xpath and what does it do? Evaluate the strengths and weaknesses of this concept, with examples.

 
Xpath looks at an XML document as a hierarchy of nodes or trees. Its primary purpose is to use a path notation that helps to navigate through the tree structure of the document. XPath is a major element in W3C’s XSLT standard – and XQuery and XPointer are both built on XPath expressions. (http://www.w3schools.com/xpath/default.asp)

Xpath, by definition looks at the structure of an XML document rather than its surface syntax. This logical structure, known as the data model, is defined in [XQuery 1.0 and XPath 2.0 Data Model (Second Edition)].] and is designed to be embedded in a host language such as XSL Transformations (XSLT) or XQuery. 

As an XML Query Language XPath has a subset that can be used for testing whether or not a node matches a pattern and this use of XPath is described in XSL Transformations (XSLT).
Xpath is concise, simple while at the same time powerful and was specifically designed for XML.  Xpath provides a single homogenous syntax and queries are compact and easy to read, key-in and understand. Furthermore, queries can be easily embedded in applications, scripts, and XML and their inherent simplicity especially for the commonly used queries, makes the queries easily and quickly parsed. With Xpath you can uniquely identify any node in an XML document and equally easily specify any path that can occur in an XML document and any set of conditions for the nodes in the path.

Xpath queries do not return repeated nodes and query conditions can be evaluated at any level of a document and are not expected to navigate from the top node of a document. Xpath also encourages queries to be declarative rather than procedural which means that emphasis is made on “what should be found” rather than “how to find it”. Xpath is also context-independent which means that it can be used in many contexts.

Xpath also has some disadvantages, the most notable of perhaps the extra resources requires both in terms of parses processing time as well  as adding another learning curve for developers to climb. Cross browser compatibility and version dependency issues also arise and can cause problems.