- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
RELATED XML RECOMMENDATIONS in Font
CHAPTER 2 RELATED XML RECOMMENDATIONS Drawing Data Matrix ECC200 In None Using Barcode drawer for Font Control to generate, create ECC200 image in Font applications. www.OnBarcode.comBarcode Drawer In None Using Barcode drawer for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.com<table width="40%"> <tr> <th>Title</th> <th>Format</th> <th>Genre</th> </tr> <xsl:for-each select="/library/DVD"> <xsl:sort select="genre"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="format"/></td> <td><xsl:value-of select="genre"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> The stylesheet starts with a stylesheet declaration. It uses the xsl prefix to denote the XSLT namespace, which is declared in the document element, <stylesheet>. You re also required to declare the version of XSLT that you re using in this case, 1.0: < xml version="1.0" encoding="UTF-8" > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> Next, the stylesheet declares the output type in this case, HTML 4.0: <xsl:output method="html" version="4.0"/> You could also choose the output method xml or 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 <html>, <head>, and opening <body> tags. I left out the DOCTYPE declaration to simplify the example: <xsl:template match="/"> <html> <head> <title>DVD Library Listing</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <table width="40%"> <tr> <th>Title</th> <th>Format</th> <th>Genre</th> </tr> Code-128 Maker In None Using Barcode drawer for Font Control to generate, create Code 128C image in Font applications. www.OnBarcode.comPDF417 Generator In None Using Barcode creator for Font Control to generate, create PDF417 image in Font applications. www.OnBarcode.comCHAPTER 2 RELATED XML RECOMMENDATIONS
Encoding UPC-A In None Using Barcode creation for Font Control to generate, create Universal Product Code version A image in Font applications. www.OnBarcode.comDraw QR Code ISO/IEC18004 In None Using Barcode creator for Font Control to generate, create QR Code ISO/IEC18004 image in Font applications. www.OnBarcode.comThe 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 (/). Drawing EAN / UCC - 13 In None Using Barcode drawer for Font Control to generate, create GS1-128 image in Font applications. www.OnBarcode.comCode11 Maker In None Using Barcode creator for Font Control to generate, create Code11 image in Font applications. www.OnBarcode.com Note Technically, the root node isn t the same as the root element. The root note is at a higher level in the Data Matrix 2d Barcode Generator In Java Using Barcode drawer for Java Control to generate, create Data Matrix image in Java applications. www.OnBarcode.comDraw DataMatrix In None Using Barcode generator for Font Control to generate, create Data Matrix ECC200 image in Font applications. www.OnBarcode.comdocument 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. Decode Code128 In Visual C#.NET Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comGenerating Code 128 Code Set C In C#.NET Using Barcode drawer for .NET Control to generate, create ANSI/AIM Code 128 image in .NET applications. www.OnBarcode.comThe 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: <html> <head> <title>DVD Libarary Listing</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <table width="40%"> <tr> <th>Title</th> <th>Format</th> <th>Genre</th> </tr> The result tree sets up the HTML document and adds a link to an external CSS stylesheet called style.css. The closing <table> and <body> tags appear after the other content that you include. The next section within the stylesheet includes each <DVD> element as a row in the table using another template. This time the template matches each <DVD> element. Because there are multiple DVD elements, it s appropriate to use an xsl:for-each statement: <xsl:for-each select="/library/DVD"> <xsl:sort select="genre"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="format"/></td> <td><xsl:value-of select="genre"/></td> </tr> </xsl:for-each> The xsl:for-each statement finds the <DVD> node using the XPath expression /library/DVD. In other words, start with the root node, locate the <library> element, and move to the <DVD> node. This statement retrieves all of the <DVD> nodes in the XML document. Barcode Encoder In Java Using Barcode generation for Java Control to generate, create Barcode image in Java applications. www.OnBarcode.comCreating Barcode In Objective-C Using Barcode maker for iPhone Control to generate, create Barcode image in iPhone applications. www.OnBarcode.comCHAPTER 2 RELATED XML RECOMMENDATIONS
Matrix Creation In .NET Using Barcode encoder for .NET framework Control to generate, create Matrix image in VS .NET applications. www.OnBarcode.comPDF-417 2d Barcode Recognizer In Visual C#.NET Using Barcode decoder for .NET framework Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comThe 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 <genre> 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 <title>, <format>, and <genre> elements. This transformation results in the following results tree: <html> <head> <title>DVD Library Listing</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <table width="40%"> <tr> <th>Title</th> <th>Format</th> <th>Genre</th> </tr> <tr> <td>Breakfast at Tiffany's</td> <td>Movie</td> <td>Classic</td> </tr> <tr> <td>Little Britain</td> <td>TV Series</td> <td>Comedy</td> </tr> <tr> <td>Contact</td> <td>Movie</td> <td>Science fiction</td> </tr> The remaining section of the stylesheet adds the closing </table>,</body>, and </html> tags: </table> </body> </html> </xsl:template> </xsl:stylesheet> 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 s 6 and 7. Decoding Barcode In VS .NET Using Barcode Control SDK for ASP.NET Control to generate, create, read, scan barcode image in ASP.NET applications. www.OnBarcode.comMaking Code 128B In VB.NET Using Barcode encoder for .NET framework Control to generate, create ANSI/AIM Code 128 image in .NET framework applications. www.OnBarcode.comPDF417 Printer In None Using Barcode creation for Excel Control to generate, create PDF 417 image in Excel applications. www.OnBarcode.comDataMatrix Decoder In None Using Barcode decoder for Software Control to read, scan read, scan image in Software applications. www.OnBarcode.com |
|