c# code 39 Applying XSLT Templates in Visual C#.NET

Creating Code-39 in Visual C#.NET Applying XSLT Templates

Applying XSLT Templates
Code-39 Maker In C#
Using Barcode generator for .NET framework Control to generate, create Code 39 image in VS .NET applications.
www.OnBarcode.com
Code 39 Extended Decoder In C#.NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
In 6, you learned to apply XSLT style sheets to XML data. You saw that XSLT allows you to transform XML data from one form to another. The same concept also can be applied in SQLXML, where you may wish to apply XSLT templates to whatever data you receive in your client application. This is accomplished by using the XslPath property of the SqlXmlCommand class. To demonstrate the use of XslPath, you need to develop an application like the one shown in Figure 10-6.
GS1-128 Drawer In Visual C#
Using Barcode encoder for .NET framework Control to generate, create EAN / UCC - 14 image in .NET framework applications.
www.OnBarcode.com
Drawing ANSI/AIM Code 39 In Visual C#
Using Barcode creation for Visual Studio .NET Control to generate, create Code 39 Full ASCII image in .NET applications.
www.OnBarcode.com
CHAPTER 10 XML IN S QL SERVE R
1D Drawer In C#
Using Barcode generation for .NET framework Control to generate, create 1D image in VS .NET applications.
www.OnBarcode.com
Barcode Generator In C#.NET
Using Barcode creator for .NET framework Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
Figure 10-6. Application to illustrate the use of the XslPath property The application consists of a Web Browser control. When the form loads, a SELECT query is executed by using SqlXmlCommand. An XSLT style sheet is then applied to the returned XML data to transform it into HTML. The resultant HTML document is then displayed in the Web Browser control. Before you write any code, you must create an XSLT style sheet named Employees.xslt as shown in Listing 10-23. Listing 10-23. Employees.xslt Markup < 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> </tr> <xsl:for-each select="root/employees"> <tr> <td> <xsl:value-of select="@EmployeeID"/> </td> <td> <xsl:value-of select="@FirstName"/> </td>
Print Data Matrix ECC200 In C#.NET
Using Barcode creation for .NET Control to generate, create ECC200 image in .NET framework applications.
www.OnBarcode.com
USPS POSTal Numeric Encoding Technique Barcode Drawer In C#
Using Barcode maker for .NET framework Control to generate, create USPS POSTal Numeric Encoding Technique Barcode image in .NET applications.
www.OnBarcode.com
CHAPTER 10 XML IN S QL SERVE R
Drawing Code 39 In None
Using Barcode drawer for Software Control to generate, create Code-39 image in Software applications.
www.OnBarcode.com
Print Code 39 In Objective-C
Using Barcode drawer for iPhone Control to generate, create Code39 image in iPhone applications.
www.OnBarcode.com
<td> <xsl:value-of select="@LastName"/> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> The style sheet iterates through all the <Employees> elements and renders an HTML table. The HTML table displays the attribute values in various cells. Note that we will be using the AUTO mode of the FOR XML clause, which returns column values as XML attributes. That is why the style sheet uses attribute names (@EmployeeID, @FirstName, and @LastName). The code that actually executes the SELECT query and performs the transformation is shown in Listing 10-24. Listing 10-24. Applying an XSLT Style Sheet private void Form1_Load(object sender, EventArgs e) { string strConn = @"Provider=SQLOLEDB;server=.\sqlexpress;database=northwind;integrated security=SSPI"; SqlXmlCommand cmd = new SqlXmlCommand(strConn); cmd.CommandText = "SELECT EmployeeID,FirstName,LastName FROM employees FOR XML AUTO"; cmd.RootTag = "root"; cmd.XslPath = Application.StartupPath + @"\employees.xslt"; StreamWriter writer = File.CreateText(Application.StartupPath + @"\sqlxmlresults.htm"); cmd.ExecuteToStream(writer.BaseStream); writer.Close(); webBrowser1.Navigate(Application.StartupPath + @"\sqlxmlresults.htm"); } Notice the code marked in bold. This time the SELECT statement doesn t contain a ROOT clause. We could indeed have used it, but the code achieves the same thing with the help of the RootTag property of the SqlXmlCommand class. Recollect that in the absence of a ROOT clause in the FOR XML query, the returned XML data doesn t contain a root element. The RootTag property of SqlXmlCommand specifies the name of the root tag inside which the output of the SELECT query will be wrapped. The XSLT style sheet to be used for transformation is specified via the XslPath property of the SqlXmlCommand class. This way, the SqlXmlCommand class knows which style sheet to apply to the returned XML data. The rest of the code should be familiar to you, as we discussed it in previous examples. It simply saves the transformed XML data into a disk file and displays that file in the Web Browser control.
Code 128 Code Set A Decoder In VB.NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Decoding Barcode In VB.NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
CHAPTER 10 XML IN S QL SERVE R
GTIN - 13 Generator In None
Using Barcode creator for Office Excel Control to generate, create EAN-13 Supplement 5 image in Microsoft Excel applications.
www.OnBarcode.com
Draw PDF-417 2d Barcode In .NET
Using Barcode encoder for Reporting Service Control to generate, create PDF-417 2d barcode image in Reporting Service applications.
www.OnBarcode.com
Writing Template Queries
PDF417 Drawer In Java
Using Barcode printer for Android Control to generate, create PDF 417 image in Android applications.
www.OnBarcode.com
Creating Barcode In Java
Using Barcode generator for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
In the preceding example, we specified the SELECT query directly in code. There is an alternative to this too: you can store the queries in an XML file and specify the path of this XML file as the CommandText of the SqlXmlCommand class. These XML files are called XML templates. The structure of this XML file can be seen in Listing 10-25. Listing 10-25. Creating an XML Template < xml version="1.0" encoding="utf-8" > <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"> <sql:header> <sql:param name='EmpID'>1</sql:param> </sql:header> <sql:query> SELECT EmployeeID,FirstName,LastName FROM Employees WHERE employeeid>@Empid FOR XML AUTO </sql:query> </ROOT> The root element <ROOT> is a user-defined element, but the namespace urn:schemasmicrosoft-com:xml-sql is necessary. The <ROOT> element contains an optional section called <sql:header>, which is used to define parameters used by your query (if any). Each parameter is specified by using a <sql:param> element. The name attribute of the <sql:param> element indicates the name of the parameter, while the value of the parameter is stored within the <sql:param> and </sql:param> tags. The actual query is stored in the <sql:query> section. The query uses the parameter by prefixing its name with the @ symbol. To use this XML template file, you need to create an application like the one shown in Figure 10-7.
EAN / UCC - 13 Maker In Java
Using Barcode printer for Android Control to generate, create EAN / UCC - 13 image in Android applications.
www.OnBarcode.com
GS1 - 13 Decoder In Visual C#
Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Barcode Encoder In None
Using Barcode drawer for Excel Control to generate, create Barcode image in Microsoft Excel applications.
www.OnBarcode.com
Draw EAN13 In Java
Using Barcode creator for Java Control to generate, create European Article Number 13 image in Java applications.
www.OnBarcode.com
Copyright © OnBarcode.com . All rights reserved.