- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
c# code 39 checksum Branching by Using <xsl:if> in Visual C#
Branching by Using <xsl:if> Code 39 Extended Encoder In Visual C# Using Barcode generator for VS .NET Control to generate, create USS Code 39 image in .NET applications. www.OnBarcode.comRead Code 39 Extended In C#.NET Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comThe XSLT standard provides the <xsl:if> element that is equivalent to the if statement provided by many programming languages. Suppose that you wish to display details only where the first name is Nancy. You can achieve this by using <xsl:if> as shown in Listing 6-5. Listing 6-5. Using <xsl:if> < xml version="1.0" encoding="UTF-8" > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h1>Employee Listing</h1> <table border="1"> <tr> <th>Employee ID</th> <th>First Name</th> <th>Last Name</th> <th>Home Phone</th> <th>Notes</th> </tr> <xsl:for-each select="employees/employee"> <xsl:if test="firstname[text()='Nancy']"> <tr> <td> <xsl:value-of select="@employeeid"/> </td> <td> <xsl:value-of select="firstname"/> </td> Code 128 Code Set C Encoder In C#.NET Using Barcode maker for .NET Control to generate, create Code128 image in VS .NET applications. www.OnBarcode.comGS1 - 13 Creator In Visual C# Using Barcode drawer for .NET framework Control to generate, create European Article Number 13 image in .NET framework applications. www.OnBarcode.comCH APT ER 6 T RANS FO RMI NG XM L WI T H XS LT
Printing PDF-417 2d Barcode In C# Using Barcode maker for .NET Control to generate, create PDF417 image in .NET applications. www.OnBarcode.comPainting Barcode In Visual C# Using Barcode creation for Visual Studio .NET Control to generate, create Barcode image in VS .NET applications. www.OnBarcode.com<td> <xsl:value-of select="lastname"/> </td> <td> <xsl:value-of select="homephone"/> </td> <td> <xsl:value-of select="notes"/> </td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> This is the same style sheet that we used in our first example, but this time, it includes the <xsl:if> construct. The test attribute of <xsl:if> tests for a specific condition. The condition in our example checks whether the value of the <firstname> element (text()) is Nancy. If it is Nancy, the details are outputted in the resultant HTML table. Figure 6-3 shows a sample view of the Employees.xml file after applying the preceding style sheet. Drawing Code 3 Of 9 In Visual C# Using Barcode maker for .NET framework Control to generate, create Code-39 image in .NET applications. www.OnBarcode.comIntelligent Mail Generation In Visual C#.NET Using Barcode encoder for VS .NET Control to generate, create 4-State Customer Barcode image in .NET framework applications. www.OnBarcode.comFigure 6-3. Output after using <xsl:if>
Making Code 3 Of 9 In Visual C#.NET Using Barcode printer for .NET Control to generate, create Code 39 image in Visual Studio .NET applications. www.OnBarcode.comCreating Code 3/9 In Java Using Barcode maker for BIRT Control to generate, create Code39 image in BIRT applications. www.OnBarcode.comBranching by Using <xsl:choose> and <xsl:when>
Draw EAN-13 Supplement 5 In None Using Barcode generator for Office Word Control to generate, create EAN 13 image in Word applications. www.OnBarcode.comPrinting Data Matrix In Java Using Barcode generation for BIRT reports Control to generate, create Data Matrix image in BIRT reports applications. www.OnBarcode.comThe <xsl:choose> and <xsl:when> elements are equivalent to the switch statement used by programming languages. Using our example file, suppose that you wish to display an additional column called Qualification in the resultant HTML table. You wish to search the notes about an employee for certain qualifications and accordingly want to display them in this additional column. Listing 6-6 shows the style sheet that accomplishes this task. Drawing Code 3 Of 9 In VS .NET Using Barcode creator for Visual Studio .NET Control to generate, create ANSI/AIM Code 39 image in Visual Studio .NET applications. www.OnBarcode.comBarcode Encoder In Java Using Barcode generation for BIRT reports Control to generate, create Barcode image in BIRT reports applications. www.OnBarcode.comC HA PTER 6 TRAN SFORM IN G XML WITH XSLT
Barcode Creator In .NET Using Barcode encoder for Reporting Service Control to generate, create Barcode image in Reporting Service applications. www.OnBarcode.comRecognize Code-128 In C#.NET Using Barcode decoder for VS .NET Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comListing 6-6. Using <xsl:choose> and <xsl:when> < xml version="1.0" encoding="UTF-8" > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h1>Employee Listing</h1> <table border="1"> <tr> <th>Employee ID</th> <th>First Name</th> <th>Last Name</th> <th>Home Phone</th> <th>Notes</th> <th>Qualification</th> </tr> <xsl:for-each select="employees/employee"> <tr> <td> <xsl:value-of select="@employeeid"/> </td> <td> <xsl:value-of select="firstname"/> </td> <td> <xsl:value-of select="lastname"/> </td> <td> <xsl:value-of select="homephone"/> </td> <td> <xsl:value-of select="notes"/> </td> <td> <xsl:choose> <xsl:when test="notes[contains(.,'BA')]"> BA (Arts) </xsl:when> <xsl:when test="notes[contains(.,'BS')]"> BS (Science) </xsl:when> <xsl:when test="notes[contains(.,'BTS')]"> BTS (Other) </xsl:when> <xsl:otherwise> Unknown </xsl:otherwise> Generate QR Code In None Using Barcode generation for Font Control to generate, create Denso QR Bar Code image in Font applications. www.OnBarcode.comBarcode Printer In Objective-C Using Barcode maker for iPhone Control to generate, create Barcode image in iPhone applications. www.OnBarcode.comCH APT ER 6 T RANS FO RMI NG XM L WI T H XS LT
Barcode Scanner In None Using Barcode reader for Software Control to read, scan read, scan image in Software applications. www.OnBarcode.comGenerate EAN128 In .NET Using Barcode creation for VS .NET Control to generate, create UCC - 12 image in .NET applications. www.OnBarcode.com</xsl:choose> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Notice the markup in bold. The <xsl:choose> element starts the switch statement. Each individual <xsl:when> element tests a specific condition. In our example, we check whether the <notes> element contains BA, BS, or BTS, and accordingly emit the qualification of the employee. If the test fails, the markup from <xsl:otherwise> is emitted. Figure 6-4 shows the table with the Qualification column added. Figure 6-4. Qualification column added by using <xsl:choose> and <xsl:when>
Transforming Elements and Attributes
Up until now, we have transformed XML data into HTML. However, often you may need to transform XML data into another XML representation. For example, a B2B application might be receiving orders electronically in XML format. While receiving such orders, you must ensure that the source XML markup and expected XML markup match. If they do not match, you can apply XSLT transformations to generate the desired markup. To illustrate how XSLT transformations can convert one XML representation into another, we will transform Employees.xml into another XML representation, as shown in Listing 6-7. C HA PTER 6 TRAN SFORM IN G XML WITH XSLT
Listing 6-7. Required XML Markup from Employees.xml < xml version="1.0" encoding="utf-8" > <EMPLOYEES> <E1 EMPCODE="1"> <FNAME>Nancy</FNAME> <LNAME>Davolio</LNAME> <PHONE>(206) 555-9857</PHONE> <REMARKS> includes a BA in psychology from Colorado State University in 1970. She also completed "The Art of the Cold Call." Nancy is a member of Toastmasters International. </REMARKS> </E1> <E2 EMPCODE="2"> <FNAME>Andrew</FNAME> <LNAME>Fuller</LNAME> <PHONE>(206) 555-9482</PHONE> <REMARKS> Andrew received his BTS commercial in 1974 and a Ph.D. in international marketing from the University of Dallas in 1981. He is fluent in French and Italian and reads German. He joined the company as a sales representative, was promoted to sales manager in January 1992 and to vice president of sales in March 1993. Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association. </REMARKS> </E2> <E3 EMPCODE="3"> <FNAME>Janet</FNAME> <LNAME>Leverling</LNAME> <PHONE>(206) 555-3412</PHONE> <REMARKS> Janet has a BS degree in chemistry from Boston College (1984). She has also completed a certificate program in food retailing management. Janet was hired as a sales associate in 1991 and promoted to sales representative in February 1992. </REMARKS> </E3> </EMPLOYEES> Notice the several changes made to the XML markup: The root node is now <EMPLOYEES> and not <employees>. Each <employee> element is replaced with an element of the form E<employeeid> that is, <E1>, <E2>, and <E3>. That means the element name consists of a constant part (E) followed by the employee ID.
|
|