ASP.NET
  Home arrow ASP.NET arrow Page 5 - 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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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 - Retrieving all values of a particular element at any level of hierarchy (or path)


    (Page 5 of 6 )

    We already retrieved all employee names using the XSLT code given in the previous section. The code given in that section always deals with the “Ename” existing only at “EmployeeDetails/Department/Employee.”

    If I have the “Ename” at different levels of the hierarchy (but not in my XML document yet), the XSLT given in the previous section will not work. The following is the modified code (using separate template) to retrieve the value of “Ename” at any level of the hierarchy:

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

    <xsl:stylesheet version="1.0"

        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

          <xsl:template match="/">

                <b>

                      <xsl:apply-templates select ="//Ename"/>

                </b>

          </xsl:template>

          <xsl:template match="Ename">

                <xsl:value-of select ="text()"/>

                <br/>

          </xsl:template>

    </xsl:stylesheet>

    You can observe that I replaced “EmployeeDetails/Department/Employee” with a simple “//Ename.”  The “//” simply gives the instruction “at any level of hierarchy.”  Similarly, the following is the modified code (using “xsl:for-each” construct) to retrieve the value of “Ename” at any level of hierarchy:

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

    <xsl:stylesheet version="1.0"

        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

          <xsl:template match="/">

                <b>

                      <xsl:for-each select="//Ename">

                            <xsl:value-of select="text()"/>

                            <br/>

                      </xsl:for-each>

                </b>

          </xsl:template>

    </xsl:stylesheet>

    The output of any of the above transformations would be the same (in this case), as given in the previous section.  You may find it different if you really have “Ename” at different levels of hierarchies (or paths).

    More ASP.NET Articles
    More By Jagadish Chaterjee


     

    ASP.NET ARTICLES

    - 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
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway