ASP.NET
  Home arrow ASP.NET arrow Working with xsl:choose in XSLT
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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

Working with xsl:choose in XSLT
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2006-12-11

    Table of Contents:
  • Working with xsl:choose in XSLT
  • Working with xsl:choose in XSLT: introduction
  • Working with xsl:choose in XSLT: explanation
  • Emitting HTML together with CSS using XSLT
  • Working with multiple xsl:when within xsl:choose in XSLT
  • More conditions within xsl:when

  • 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


    Working with xsl:choose in XSLT


    (Page 1 of 6 )

    This is the second article in a series focusing on developing XSLT-oriented applications using ASP.NET 2.0. Even though the series is based on ASP.NET 2.0, I use it only as a transformation engine. The entire focus will be on working with XSLT. You can use any transformation engine according to your requirements (such as Java or others).
    A downloadable zip file is available for this article.

    In this article, I will be focusing on working with the “xsl:choose” construct available in XSLT.  This article is heavily dependent on the first article of this series, especially when working with ASP.NET 2.0.  If you come across any problems, I strongly suggest you go through my first article.

    The entire solution (source code) for this article is available for free download (in the form of a zip).  All the applications in this series have been developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Standard Edition together with Microsoft SQL Server 2005 Developer Edition as the database.  You can even directly copy and paste the code given in this article and save with extensions XML or XSL and work with your own XSL parsers/engines.

    I didn’t really test any of the code in any other tools/IDEs/servers/editions/versions. If you have any problems, please feel free to post in the discussion area.

    Setting up your environment

    To work with this article, I set up a new database table called “emp” with the fields empno, ename, sal and deptno. I also inserted a few sample rows. Once you execute the following query using “getXMLContent” method:

    select Empno,Ename,Sal,Deptno from dbo.emp

    You are likely to receive the following XML upon the execution of above SELECT command:

    <SQLData>

          <Rows>

                <Empno>1001</Empno>

                <Ename>Jag</Ename>

                <Sal>4400</Sal>

                <Deptno>10</Deptno>

          </Rows>

          <Rows>

                <Empno>1002</Empno>

                <Ename>Chat</Ename>

                <Sal>2800</Sal>

                <Deptno>20</Deptno>

          </Rows>

          <Rows>

                <Empno>1003</Empno>

                <Ename>Winner</Ename>

                <Sal>3700</Sal>

                <Deptno>10</Deptno>

          </Rows>

          <Rows>

                <Empno>1004</Empno>

                <Ename>Dhan</Ename>

                <Sal>5000</Sal>

                <Deptno>20</Deptno>

          </Rows>

    </SQLData>

    I also included a sample XSLT which works with the above XML document to test the accuracy of XML generation. The XSLT is as follows:

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

    <xsl:stylesheet version="1.0"

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

          <xsl:template match="/">

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

          </xsl:template>

          <xsl:template match="SQLData/Rows/Ename">

                      <xsl:value-of select="."/>

                <br />

          </xsl:template>

    </xsl:stylesheet>

    Once the above is executed, you should be given a list of all employee names. I also modified the code in such a way that it clearly lists the transformation. The following is the new code:

    Dim xslt As New Xsl.XslCompiledTransform()

        xslt.Load(Server.MapPath("XSLTFile11.xsl"))

        ' Create the writer.

        Dim settings As New XmlWriterSettings()

        settings.Indent = True

        settings.IndentChars = ControlChars.Tab

        settings.ConformanceLevel = ConformanceLevel.Auto

        Dim sw As New IO.StringWriter

        Dim writer As XmlWriter = XmlWriter.Create(sw, settings)

        ' Execute the transformation.

        xslt.Transform(docXML, writer)

        writer.Close()

        Me.Literal1.Text = "<pre>" & Server.HtmlEncode(sw.ToString) & "</pre>"

        sw.Close()

    More ASP.NET Articles
    More By Jagadish Chaterjee


     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek