ASP.NET
  Home arrow ASP.NET arrow Page 2 - Learning XPath with XSLT using ASP.NET 2.0
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Learning XPath with XSLT using ASP.NET 2.0
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-01-02

    Table of Contents:
  • Learning XPath with XSLT using ASP.NET 2.0
  • Setting up your environment: XML Schema and XML
  • Setting up your environment: ASP.NET 2.0 code and XSL
  • Retrieving all values of a particular element at a particular level of hierarchy (or path)
  • Retrieving all values of a particular element at any level of hierarchy (or path)
  • Retrieving all values of all elements at all levels of hierarchies (or paths)

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Learning XPath with XSLT using ASP.NET 2.0 - Setting up your environment: XML Schema and XML


    (Page 2 of 6 )

    In this article, we need to work with nested hierarchies in XML. None of my XML samples in previous articles will really help us. So I started defining my own XML schema and sample XML document for this article.

    In this new design, I included the concept of departments and employees. Every department can contain any number of employees and an employee always belongs to a table. The following is the XML schema to achieve the same:

    <?xml version="1.0" encoding="utf-8"?>

    <xs:schema id="EmployeeDetails" targetNamespace=
    "http://tempuri.org/EmployeeDetails.xsd" 
    elementFormDefault="qualified" xmlns=
    "http://tempuri.org/EmployeeDetails.xsd" xmlns:mstns=
    "http://tempuri.org/EmployeeDetails.xsd" xmlns:xs=
    "http://www.w3.org/2001/XMLSchema">

          <xs:element name="EmployeeDetails">

                <xs:complexType>

                      <xs:sequence>

                            <xs:element name="Department" maxOccurs="unbounded">

                                  <xs:complexType>

                                        <xs:sequence>

                                              <xs:element name="Employee" maxOccurs="unbounded">

                                                    <xs:complexType>

                                                          <xs:sequence>

                                                                <xs:element name="Empno" type="xs:int" />

                                                                <xs:element name="Ename" type="xs:string" />

                                                                <xs:element name="Sal" type="xs:float" />

                                                          </xs:sequence>

                                                    </xs:complexType>

                                              </xs:element>

                                        </xs:sequence>

                                        <xs:attribute name="Deptno" type="xs:int" />

                                        <xs:attribute name="Dname" type="xs:string" />

                                        <xs:attribute name="Location" type="xs:string" />

                                  </xs:complexType>

                            </xs:element>

                      </xs:sequence>

                </xs:complexType>

          </xs:element>

    </xs:schema>

    I designed the above schema using Visual Studio 2005. From the above you can understand that the root of the XML document must start with “EmployeeDetails” and can contain any number of “Departments.”  Details (deptno, dname and location) of each and every “Department” will be available as attributes and every “Department” can have any number of “Employees” with details (empno, ename and sal) underneath them.  

    The following is the sample XML document which complements the above schema.

    <?xml version="1.0" encoding="utf-8"?>

    <EmployeeDetails>

          <Department Deptno="10" Dname="Accounting" Location="New York">

                <Employee>

                      <Empno>1001</Empno>

                      <Ename>Jagadish</Ename>

                      <Sal>3400</Sal>

                </Employee>

                <Employee>

                      <Empno>1002</Empno>

                      <Ename>Chatarji</Ename>

                      <Sal>2500</Sal>

                </Employee>

                <Employee>

                      <Empno>1003</Empno>

                      <Ename>Winner</Ename>

                      <Sal>4300</Sal>

                </Employee>

          </Department>

          <Department Deptno="20" Dname="Sales" Location="Dallas">

                <Employee>

                      <Empno>2001</Empno>

                      <Ename>Dhanam</Ename>

                      <Sal>4500</Sal>

                </Employee>

                <Employee>

                      <Empno>2002</Empno>

                      <Ename>Chinna</Ename>

                      <Sal>3400</Sal>

                </Employee>

                <Employee>

                      <Empno>2003</Empno>

                      <Ename>Pedda</Ename>

                      <Sal>3200</Sal>

                </Employee>

          </Department>

          <Department Deptno="30" Dname="Research" Location="Washington">

                <Employee>

                      <Empno>3001</Empno>

                      <Ename>Ram</Ename>

                      <Sal>5600</Sal>

                </Employee>

                <Employee>

                      <Empno>3002</Empno>

                      <Ename>Robert</Ename>

                      <Sal>5600</Sal>

                </Employee>

                <Employee>

                      <Empno>3003</Empno>

                      <Ename>Rahim</Ename>

                      <Sal>4300</Sal>

                </Employee>

          </Department>

    </EmployeeDetails>

    More ASP.NET Articles
    More By Jagadish Chaterjee


     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT