Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

SQL Server
SQL Server Automating Administration
SQL Server Full Text Searching
SQL Server Installing
SQL Server Selecting XML Data
SQL Server XSL Stylesheets
SQL Server Stored Procedures
SQL Server XDR Schemes
SQL Server Indexed Views
SQL Server Introduction
SQL Server Data Statements
SQL Server SELECT Statement
SQL Server Modification Statements
SQL ServerTransaction Statements
SQL Server Schema Statements
SQL Server XML Introduction
SQL Server XML Templates

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


SQL Sserver 2000 And XML Part 3 - XSL Stylesheets


Previoushome Next






SQL Sserver 2000 And XML Part 3 - XSL Stylesheets


A D V E R T I S E M E N T

 

We have seen how XML data is displayed in a browser from the examples that we have executed. While the data displayed is well formed and we can identify the various elements in the XML document, it really does not provide the type of data that we would want to display in a browser.

XSL helps solve this problem; it is an acronym for Extensible Stylesheet Language and describes the way that XML data should be formatted and displayed. Like XML, XSL also uses tags to describe and format the XML data. Each tag has a corresponding closing tag that begins with a forward slash (/). XSL, like XML, uses strict formatting standards to create well-formed documents.

Using XSL we can define a stylesheet. This can contain an entire HTML document within the XSL document. The HTML is intermixed with XSL elements and will be merged with the resulting XML data to form a completed HTML document that will be displayed in a browser.

An XSL file is like an XML file, but for stylesheets, and must begin with the XML declaration. The following code fragment shows the beginning of an XSL stylesheet:

<?xml version="1.0" encoding="UTF-8"?>     
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">  
<xsl:template match = "/">                

The first line of code here is the XML declaration, which is included as the first line of every XML document.

The next line of code is the <xsl:stylesheet> element that defines this XML document as an XSL stylesheet. It should be noted here that your XSL stylesheets will have a .xsl file extension. Within the <xsl:stylesheet> element we have declared a namespace of xmlns:xsl=http://www.w3.org/TR/WD-xsl. This is the standard namespace supported by Microsoft Internet Explorer 5.0. A namespace allows you to declare elements of a certain namespace and differentiate these elements from others of the same name. In other words you can specify a collection of names that can be used as element or attribute names in your document.

At this point it is worth noting that, like XML, XSL is also case sensitive. This includes the elements themselves and their attributes.

Following the <xsl:stylesheet> element we declare the <xsl:template> element to indicate that the stylesheet template corresponds to the root element of the XML document. We are going to look at how to use templates in a little while.

These three lines of code are the standard beginning of every XSL stylesheet that you will create. Keep in mind that the <xsl:stylesheet> and <xsl:template> elements require a closing tag at the end of the stylesheet, as shown:

</xsl:template>                      
</xsl:stylesheet>

The XSL language provides many elements that help us to process and display XML data. We can even include VBScript or JScript/JavaScript in our XSL stylesheets, although that is beyond the scope of this chapter. At the core of XSL is the <xsl:for-each> element that sets up a loop for processing XML data.

This element accepts the select attribute, which specifies the XSL pattern for the node of XML data to be iterated. A node is an element in the XML tree structure that has links to one or more nodes below it. An example of this is shown in the next code fragment:

<xsl:for-each select="Employees/Employee_T">

The nodes that we have specified in the select attribute specify the root node of Employees and a sub node of Employee_T. Let's take a look again at the figure we saw earlier. The root node is listed as Employees and the sub-node under the root is listed as Employee_T, which is the name of our table. SQL Server placed this node name here automatically for us and derived the name from the table name.

Notice that for each Employee_T node there are several XML attributes that we want to process, such as Employee_ID, First_Name_VC, and Last_Name_VC. These are processed using the <xsl:value-of> element.

The code fragment below shows how we use the <xsl:value-of> element. The select attribute specifies the pattern to match and the data from this match is then inserted as a text string into your document. Because our data is being generated from SQL Server we must specify the 'at' sign (@) before the element name to be matched. After the pattern name we include a forward slash to indicate the closing of this element.

<xsl:value-of select="@Employee_ID "/>  
<xsl:value-of select="@First_Name_VC"/>  
<xsl:value-of select="@Last_Name_VC"/>

This demonstrates the point made earlier; remember that while all XML and XSL elements require a closing tag, we can sometimes specify a forward slash at the end of the element to indicate a closing tag for that element, such as we have done in the previous code fragment.

Try It Out - XSL Stylesheet

Now that we know the basic elements that make up an XSL stylesheet, let's create one to display the first and last name of all employees from the Employee_T table.

1. To create this stylesheet you can use any text editor you want; the complete code for this XSL stylesheet is listed below:

<?xml version="1.0" encoding="UTF-8"?>     
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">  
<xsl:template match = "/">                
  <HTML>                         
  <HEAD>                        
  <STYLE>
  TH 
  { 
   background-color: #CCCCCC;
  }
  </STYLE>  
  </HEAD>                        
  <BODY>                        
  <TABLE Border="1">        
   <TR>
     <TH ColSpan="2">Hardware Tracking Employees</TH>
   </TR>      
   <TR>
     <TH>First Name</TH>
     <TH>Last Name</TH>
   </TR>  
   <xsl:for-each select="Employees/Employee_T">
     <TR>                          
      <TD><xsl:value-of select="@First_Name_VC"/></TD>   
      <TD><xsl:value-of select="@Last_Name_VC"/></TD>
     </TR>      
   </xsl:for-each>                   
  </TABLE>                       
  </BODY>                        
  </HTML>                         
</xsl:template>                      
</xsl:stylesheet>

2. Once you have entered the code save the stylesheet in the htData directory as Employee.xsl. On my machine I created the htData directory under the \Inetpub\wwwroot\ directory.

3. We can test this XSL stylesheet by running another query in the URL of our web browser. Enter the following URL in your browser and press the Enter key:

http://localhost/htData?SQL=SELECT+First_Name_VC,
+Last_Name_VC+FROM+Employee_T+FOR+XML+
AUTO&XSL=Employee.xsl&ContentType=Text/HTML&Root=Employees

You should now see results similar to those shown in the following screenshot:

 



Be the first one to comment on this page.




  SQL Server eBooks

No eBooks on SQL Server could be found as of now.

 
 SQL Server FAQs
More Links » »
 
 SQL Server Interview Questions
More Links » »
 
 SQL Server Articles
More Links » »
 
 SQL Server News
More Links » »
 
 SQL Server Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: SQL Sserver 2000 And XML Part 3 - XSL Stylesheets, SQL Server, SQL Server, SQL Server Tutorial, SQL Server tutorial pdf, history of SQL Server, SQL Server Administration, learn SQL Server

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright 2003-2017 Vyom Technosoft Pvt. Ltd., All Rights Reserved.