ASP
  Home arrow ASP arrow Page 3 - XSL Device Formatting Using the Microsoft ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
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

XSL Device Formatting Using the Microsoft XSL ISAPI Filter
By: Jean-Baptiste Minchelli
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2002-03-26

    Table of Contents:
  • XSL Device Formatting Using the Microsoft XSL ISAPI Filter
  • Installing the filter
  • Our sample application
  • Conclusion

  • 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


    XSL Device Formatting Using the Microsoft XSL ISAPI Filter - Our sample application


    (Page 3 of 4 )

    The following code example represents a small application that presents a list of numbers on a single page. Because both WML devices (WAP phones) and HTML devices (Web browsers) will use this application, we will need two stylesheets. In addition, we will also need the .pasp file that will generate the XML as well as a configuration file that will specify which stylesheet should be applied to which device.

    The ASP source for generating the XML page (test.pasp) looks like this:

    <?xml version="1.0" ?>

    <?xml-stylesheet type="text/xsl" server-config="test-Config.xml" href="test-IE5.xsl" ?>

    <numbers>

    <%

    i = 5

    while (i > 0)

    response.write "<number>" & i & "</number>"

    i = i - 1

    wend

    %>

    </numbers>


    The code shown represents the .pasp file. This will generate an XML document. In fact, it's simply an ASP file that will generate XML instead of the "regular" HTML.

    The XML generated by test.asp looks like this (Note that you will never actually see this XML):

    <?xml version="1.0" ?>

    <?xml-stylesheet type="text/xsl" server-config="test-Config.xml" href="test-IE5.xsl" ?>

    <numbers>

    <number>5</number>

    <number>4</number>

    <number>3</number>

    <number>2</number>

    <number>1</number>

    </numbers>


    For each XML document, it's necessary to specify a configuration file that will determine the appropriate XSL stylesheet to use for any given device. The configuration file for our sample application is called test-Config.xml and is shown below:

    <?xml version="1.0" ?>

    <server-styles-config>

    <!-- for WML 1.1 browsers -->

    <device target-markup="WML1.1">

    <stylesheet href="test-WML11.xsl"/>

    </device>

    <!-- for Others browsers -->

    <device>

    <stylesheet href="test-IE5.xsl"/>

    </device>

    </server-styles-config>


    The target-markup attribute value of the device element in the code above must exist in the browscap.ini file. The XSL ISAPI filter uses the associated information as the Content-type for the requests output.

    IIS will apply the associated stylesheet to the first matching device. In the above case, if the device accepts WML1.1, IIS will apply test-WML11.xsl -- otherwise it will apply test-IE5.xsl. For browsers like IE 5.5 that can process XSL on their own, developers can choose to leave the XML untouched. For such client-side XSL processing, the XML will be sent to the browser, which will use the specified stylesheet to format the document.

    Here's the HTML XSL stylesheet, which is called test-IE5.xsl:

    <?xml version="1.0" ?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

    <xsl:template match="/">

    <HTML>

    <BODY>

    <xsl:for-each select="numbers/number">

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

    <br/>

    </xsl:for-each>

    </BODY>

    </HTML>

    </xsl:template>

    </xsl:stylesheet>


    Here, the XSL file is associated with the default browser. It will output the content of the NUMBERS/NUMBER elements as HTML:

    The result on I.E. 6.0

    The HTML that's sent to the browser looks like this:

    <HTML>

    <BODY>

    5

    <br />

    4

    <br />

    3

    <br />

    2

    <br />

    1

    <br />

    </BODY>

    </HTML>


    The WML XSL stylesheet (test-WML11.xsl) looks like this:

    <?xml version="1.0" ?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

    <xsl:template match="/">

    <xsl:pi name="xml">version="1.0"</xsl:pi>

    <xsl:doctype>wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"</xsl:doctype>

    <wml>

    <card>

    <p>

    <xsl:for-each select="numbers/number">

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

    <br/>

    </xsl:for-each>

    </p>

    </card>

    </wml>

    </xsl:template>

    </xsl:stylesheet>


    This stylesheet will be applied to a WML enabled device, as shown below:

    Our page in the OpenWave SDK

    The WML generated by the XSL stylesheet looks like this:

    <?xml version="1.0"?>

    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

    <wml>

    <card>

    <p>

    5

    <br />

    4

    <br />

    3

    <br />

    2

    <br />

    1

    <br />

    </p>

    </card>

    </wml>

    More ASP Articles
    More By Jean-Baptiste Minchelli


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







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