Xalan Java Version

We’ll start with the Xalan Java version of the extension. The return type of the extension element is org.w3c.dom.Element. To start with, we’ll look at the XSLT stylesheet that controls everything:

<?xml version="1.0"?>
<!-- xalan-photo-album.xsl -->
<xsl:stylesheet version="1.0" 
  <xsl:output method="html"/>

  <xsl:template match="photo-album">
        <title>Photo album extension element test</title>
      <body style="font-family: sans-serif;">
          <xsl:when test="element-available('xpa:XalanPhotoAlbum')">
            <h1>Xalan photo album extension element test</h1>
              <i>[Sorry, the photo album function is not available.]</i>


Here’s the code for the extension element:

 * XalanPhotoAlbumExtension.java
 * Created on Nov 28, 2006 by Doug Tidwell

package com.oreilly.xslt.xalan;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.xalan.extensions.XSLProcessorContext;
import org.apache.xalan.templates.ElemExtensionCall;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

//This class creates a photo album with all of the images in a ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.