O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

.NET Version

The .NET version of the photo album is slightly different. We’ll implement the extension as an extension function, not as an extension element. We’ll do this to show an alternate technique for creating nodes in the output tree.

Our extension function creates a DOM tree that contains all of the HTML elements needed for the output tree. The Xalan and Saxon versions of this extension element replace the extension element in the stylesheet with the appropriate generated nodes. In the .NET environment, our extension function returns a DOM tree that is added to the result tree.

Here’s the code for the extension function. It follows the same basic procedure as the other versions of the extension: use system functions to get the list of files and then create the DOM elements for the HTML table:

/* 
 * PhotoAlbum.cs
 * Created on Nov 28, 2006 by Doug Tidwell
 */

using System;
using System.IO;
using System.Text;
using System.Xml;

// This class creates a photo album with all of the images in a 
// given directory.
namespace com.oreilly.xslt
{
  class PhotoAlbum
  {
    // getPhotoListing is the name of the extension function.  Notice 
    // that it returns an XMLNode; that node is inserted into the 
    // output tree. 
    public XmlNode getPhotoListing(String dirName,
                                   String imgPerRow,
                                   String incFilenames)
    {
      // For parameters, we get the name of the directory, the number 
      // of images per row, and whether the names of the files should 
      // be displayed. int imagesPerRow = int.Parse(imgPerRow); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required