Web site design – CHAPTER 2 RELATED XML RECOMMENDATIONS Simple Links

CHAPTER 2 RELATED XML RECOMMENDATIONS Simple Links A simple link connects a single source to a single target, much like an XHTML link. Before you can include an XLink, the XML document that includes the XLink must also include a reference to the XLink namespace. You can do this in the document element as follows: By convention, developers use xlink to preface this namespace. In XHTML, the element indicates a link. Web browsers understand the meaning of this element and display the link accordingly. In XML, you can add a link to any element within the XML document. Let s look at an example of a simple link: Here is a linked element This XLink provides a link to http://www.apress.com. It includes an xlink:type attribute indicating that it s a simple link. It uses the attribute xlink:href to provide the address of the link. The link has a title that is intended to be read by humans. The XLink includes an xlink:show behavior of replace, which indicates that the link should replace the current URL. You could also specify xlink:show = “new”, which is akin to the XHTML target=”_blank”. Other values include embed, other, and none. Choosing embed is similar to embedding an image in an XHTML page the target resource replaces the link definition in the source. A value of other leaves the link action up to the implementation and indicates that it should look for other information in the link to determine its behavior. The value none also leaves the behavior up to the implementation, but with no hints in the link. The xlink:activate attribute determines when the link opens. In this example, using onRequest indicates that the document will await user action before activating the link. The attribute could also use values of onLoad, other, or none. Setting the attribute value to onLoad causes the link to be followed immediately after the resource loads. You could use this value with xlink:show=”embed” to create a display from a set of linked source documents. The values other and none have the same meanings as in the xlink:showattribute. The preceding example creates a link that s very similar to a traditional XHTML link, with some additional capabilities. An extended XLink offers much more powerful capabilities.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision
best web hosting services

CHAPTER 2 RELATED XML RECOMMENDATIONS XPath Summary

CHAPTER 2 RELATED XML RECOMMENDATIONS XPath Summary The following list summarizes the main points to consider when working with XPath expressions: You can use XPath in XSLT stylesheets and XPointers to specify a location in an XML tree. XPath expressions identify the location using an axis name, a node test, and, optionally, a predicate. The expressions read from left to right with each point in the path separated by a forward slash (/). You can abbreviate some XPath expressions to use a shortened form. You can include mathematical operators and functions within an XPath expression if you want to perform calculations during a transformation. You saw earlier that XPath expressions specify locations in XSLT stylesheets. These expressions can also be used in XPointers, which point to a specific location within an XLink. Before we see this, let s look at XLinks. Linking with XML XLinks provide a powerful alternative to traditional XHTML links. XHTML links allow you to link from a source to a destination point, in one direction. XLinks allow you to Create two-way links Create links between external documents Change the behavior of links so that they trigger when a page loads Specify how the linked content displays You can find out more about the W3C XLink recommendation at http://www.w3.org/TR/ 2001/REC-xlink-20010627/. The XPointer recommendation is split into the element (http:// www.w3.org/TR/2003/REC-xptr-element-20030325/), the framework (http://www.w3.org/TR/ 2003/REC-xptr-framework-20030325/), and the xmlns scheme (http://www.w3.org/TR/2003/ REC-xptr-xmlns-20030325/). At the time of writing, a fourth recommendation is in development the xpointer() scheme (http://www.w3.org/TR/2002/WD-xptr-xpointer-20021219/). This recommendation adds advanced functionality to XPointer, including the ability to address strings, points, and ranges within an XML document. Currently, XML tools offer very limited support for XLink and XPointer. However, the recommendations are important and their usage is likely to be extended in the future, so it s worthwhile having an understanding of how they fit into the XML framework. Let s start by looking at the two different types of XLink that you can create: simple and extended.
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

CHAPTER 2 (Web hosting e commerce) RELATED XML RECOMMENDATIONS preceding-sibling

CHAPTER 2 RELATED XML RECOMMENDATIONS preceding-sibling parent self The axis names are self-explanatory; it s beyond the scope of this book to go into them in too much detail. It s worth mentioning, however, that you can write a shortened form of XPath expressions for the child, parent, and self axes. Table 2-3 provides some examples of the long and short forms of expressions. Table 2-3. Examples of Long and Short Forms of XPath Expressions Long Form Abbreviation child::DVD DVD DVD/attribute::id DVD/@id self::node() . parent::node() .. You saw the use of abbreviated XPath expressions in the previous section on XSLT. For example, you could refer to the nodes using /library/DVD. When you want to refer to a child node, use title rather than child::title. Identifying Specific Nodes XPath allows you to navigate to a specific node within a collection by referring to its position: /library/DVD[2] This expression refers to the second node within the node. You also can apply a filter within the expression: /library/DVD/[genre='Comedy'] The preceding expression finds the nodes with a child node containing Comedy. Including Calculations and Functions XPath expressions can include mathematical operations, and you can use the + (addition), (subtraction), * (multiplication), div (division), and mod (modulus) operators. Obviously, you can t use the / symbol for division because it s included in the location path. These expressions might be useful if you want to carry out calculations during a stylesheet transformation. You can also include functions within XPath expressions. These include node set, string, Boolean, and number functions. Again, it s beyond the scope of this book to explore these in detail, but it s useful to know that they exist. If you want to find out more about the XPath recommendation, visit http://www.w3.org/TR/1999/REC-xpath-19991116.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

CHAPTER 2 RELATED XML RECOMMENDATIONS Processing (Web hosting service)

CHAPTER 2 RELATED XML RECOMMENDATIONS Processing instructions Comments Namespaces The root node is the starting point for the XML document tree, and there s only one root node in an XML document. The XML document itself is a node in the tree, and it s a child of the root node. Other children of the root node include processing instructions and comments outside of the document node. You write XPath expressions to locate specific nodes in the tree. XPath Expressions XPath expressions use an axis name and two colon characters (::) to identify nodes in the XML document: /axis::nodetest[predicate] XPath expressions include location paths that you read from left to right to identify the different parts of an XML document. The expression separates each step in the path with a slash (/): /axis::nodetest[predicate]/axis::nodetest[predicate] These paths indicate how nodes relate to each other and their context. The starting point of the path provides the context for the node. Using a slash means that the root element provides the context. The processor evaluates XPath expressions without this character against the current node. The axis or axes used in the path describe these relationships. The nodetest identifies the node to select. It may optionally include one or more predicates that filter the selection. The following expression refers to any descendants of the root element. The root element provides the context. The descendant axis specifies that the expression should select the descendants of the node: /descendant::DVD XPath recognizes the following axes: ancestor ancestor-or-self child descendant descendant-or-self following following-sibling preceding
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services

CHAPTER 2 RELATED XML RECOMMENDATIONS XSLT Summary

CHAPTER 2 RELATED XML RECOMMENDATIONS XSLT Summary This section shows some of the functionality of XSLT, and you should remember these key points: CSS applies styles to an XML document based on the current structure of the document tree. This is called a push model. XSLT can transform a source XML document into any well-formed XML document that can be serialized as XML, HTML, or text. XSLT stylesheets can produce a result tree in a different order from the source tree. XSLT can add text and markup during the transformation. XSLT is template-based, making it mainly a declarative language. XSLT makes extensive use of XPath to locate nodes in the source tree. I ve mentioned XPath during this discussion of XSLT, so it s worthwhile exploring it in a little more detail. XPath You saw that the XSLT stylesheet relied heavily on the use of XPath to locate specific parts of the source XML document tree. Other recommendations, such as XPointer, also rely on the XPath specification, so it s useful to have an understanding of the basics. One important thing to realize is that XPath doesn t use XML rules to construct expressions. You use XPath by writing expressions that work with the XML document tree. Applying an XPath expression to a document returns one of the following: A single node A group of nodes A Boolean value A floating point number A string XPath expressions can t address the XML declaration in a document because it isn t part of the document tree. They also don t address embedded DTD declarations or blocks of CDATA. XPath treats an XML document as a hierarchical tree made up of nodes. Each tree contains Element nodes Attribute nodes Text nodes
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services

How to cite a web site – CHAPTER 2 RELATED XML RECOMMENDATIONS The next

CHAPTER 2 RELATED XML RECOMMENDATIONS The next statement dictates the sorting for the group of nodes using the xsl:sort statement. In this case, the stylesheet sorts in order of the genre. Because the template refers to the /library/DVD path, it s appropriate to use a relative path to specify the node. Within the xsl:for-each statement, the xsl:value-of element selects a specific element for inclusion in the table cell. The stylesheet repeats the statement three times one for each of the

The remaining section of the stylesheet adds the closing

Title Format Genre
Breakfast at Tiffany’s Movie Classic
Little Britain TV Series Comedy
Contact Movie Science fiction

,, and tags:

If you want to see some of the power of XSLT, you can modify the stylesheet to change the sort order. You can also filter the content to display specific records; you ll see this in Chapters 6 and 7.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision christian web host services

CHAPTER 2 RELATED XML RECOMMENDATIONS The first

CHAPTER 2 RELATED XML RECOMMENDATIONS The first line specifies what nodes in the source tree the template matches. It uses an XPath expression to determine the node. You ll find out more about XPath a little later in the chapter. In this case, you re matching the root node, which is indicated by a slash (/). Note Technically, the root node isn t the same as the root element. The root note is at a higher level in the document and has the root element as a child. This allows the stylesheet to access information in the prolog and epilog, as well as information in elements. The template specifies what should happen when the XSLT processor encounters the root. In this case, the result tree includes the HTML tags indicated within the template. It should generate the following output:

The result tree sets up the HTML document and adds a link to an external CSS stylesheet called style.css.The closing

Title Format Genre
and tags appear after the other content that you include. The next section within the stylesheet includes each element as a row in the table using another template. This time the template matches each element. Because there are multiple DVD elements, it s appropriate to use an xsl:for-each statement:

The xsl:for-eachstatement finds the node using the XPath expression /library/DVD. In other words, start with the root node, locate the element, and move to the node. This statement retrieves all of the nodes in the XML document.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision personal web hosting services


Title Format Genre

The stylesheet starts with a stylesheet declaration. It uses the xsl prefix to denote the XSLT namespace, which is declared in the document element,
. You re also required to declare the version of XSLT that you re using in this case, 1.0: Next, the stylesheet declares the output type in this case, HTML 4.0: You could also choose the output method xmlor text. If you choose the output type xml, you can generate well-formed XML or XHTML. The output type text is useful if you want to create a comma-delimited file for import into a spreadsheet or database. The next section of the stylesheet uses a template to generate the , , and opening tags. I left out the DOCTYPE declaration to simplify the example:

Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services

Shared web hosting – CHAPTER 2 RELATED XML RECOMMENDATIONS result tree

CHAPTER 2 RELATED XML RECOMMENDATIONS result tree will usually be serialized as XHTML. You can also produce printed output from the result tree with XSL-FO. Nowadays, when someone refers to XSL, they re usually referring to XSLT. You can use XSL-FO to produce a printed output, a PDF file, or perhaps an aural layout. Understanding XSLT I ll delve into XSLT in much more detail in Chapters 6 and 7, but here I ll work through a simple example so you can see the power of XSLT. You ll see how to use XSLT to convert your DVD document into an XHTML page that includes CSS styling. This process is different from styling the XML content directly with CSS, which I ll cover in Chapter 5. Earlier, you saw that CSS styles the source document using a push model, where the structure of the input defines the structure of the output. XSLT allows both a push model and a pull model, where the structure of the stylesheet defines the structure of the output. In this example, you ll see how to use both. You ll use the source document to define the display order, but the stylesheet will provide the structuring information. You ll create a list of all DVDs to display in a table on an XHTML page, and you ll add a little CSS styling to improve the appearance. You can find the files used in the example saved as dvd_XSLT.xml and dvdtoHTML.xsl. They are saved within this chapter s ZIP file in the Source Code area of the Apress web site (http://www.apress.com). Figure 2-4 shows the web page produced by the XSLT stylesheet. Figure 2-4. The transformed dvd.xml document shown in Internet Explorer The web page is created by applying the following stylesheet to the source XML document:
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

Web server version – CHAPTER 2 RELATED XML RECOMMENDATIONS XML and

CHAPTER 2 RELATED XML RECOMMENDATIONS XML and CSS You can use CSS with XML in exactly the same way that you do with XHTML. This means that if you know how to work with CSS already, you can use the same techniques with XML. I ll discuss CSS and XML in more detail in Chapter 5; this section just covers some of the main points. To display an XML document with CSS, you need to assign a style to each XML element name just as you would with XHTML. In XML, one difference is that the stylesheet is associated with an XML document using a processing instruction placed immediately after the XML declaration: In XHTML pages, the text that you wish to style is character data. With XML, that might not be the case. For example, the content might consist of numeric data that a human can t easily interpret visually. When working in CSS, it s not easy to add explanatory text when rendering the XML document. This limitation might not be important when you re working with documents that contain only text, but it might be a big consideration when you re working with other types of content. Another limitation of CSS is that it mostly renders elements in the order in which they appear in the XML document. It s beyond the scope of CSS to reorder, sort, or filter the content in any way. When displaying XML, you may need more flexibility in determining how the data should be displayed. You can achieve this by using XSL. XSL Extensible Stylesheet Language (XSL) is divided into two parts: XSL Transformations (XSLT) and XSL Formatting Objects (XSL-FO). The former transforms the source XML document tree into a results tree, perhaps as an XHTML document. The latter applies formatting, usually for printed output. Figure 2-3 shows how these two processes relate. Figure 2-3. Applying a transformation and formatting to an XML document Once the XSLT processor reads the XML document into memory, it s known as the source tree. The processor transforms nodes in the source tree using templates in a stylesheet. This process produces result nodes, which together form a result tree. The result tree is also an XML document, although you can convert it to produce other types of output. The conversion process is known as serialization. As I mentioned earlier, the
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services

Title Format Genre