Using an Extension Function in Stylus Studio

The process of using an extension function in Stylus Studio involves three main steps:

1. First, you need to write a Java class that can be used from within a stylesheet. In this example, the SystemDate() method returns the system date and time as a string:
import java.util.Date; 
               
public class SystemUtils 
               
{ 
               
   public Object SystemDate() 
               
   { 
               
     Date d = new Date(); 
               
     String s = d.toString(); 
               
     return s; 
               
   } 
               
}
               

            
2. Second, compile your class and register it on the Stylus Studio host by copying the .class file to a location defined in the host's CLASSPATH environment variable.
3. Finally, specify information in the stylesheet so that Stylus Studo can use your class. You do this with a namespace reference in the xsl:stylesheet tag. For example, define a namespace as xmlns:Ext where Ext is the prefix to use when calling the class methods. ( Ext is not a predefined keyword; it can be replaced by any other legal string.) The namespace reference then takes the class name as a value. In this example, the whole reference looks like the following:
xmlns:Ext="SystemUtils" 
               

            

The class is now available from within the stylesheet and can be used in a template such as the following:

<xsl:template match="NODE"> 
               
   <p><xsl:value-of select="Ext:SystemDate()"/></p> 
               
</xsl:template>
               

            

The XSLT stylesheet might look like the following:

<?xml version="1.0" encoding="ISO-10646-UCS-2"?> 
               
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform" 
               
xmlns:Ext="SystemUtils"> 
               
   <xsl:param name="param">test</xsl:param> 
               
   <xsl:template match="*|/">
               
      <xsl:apply-templates/>
               
   </xsl:template> 
               
   <xsl:template match="text()|@*">
               
     <xsl:value-of select="."/>
               
   </xsl:template> 
               
   <xsl:template match="NODE"> 
               
     <p><xsl:value-of select="Ext:SystemDate()"/></p> 
               
   </xsl:template> 
               
</xsl:stylesheet>
               

            

EDI to XML Mapping

A tutorial on how to transform EDI files into XML using Stylus Studio's Convert to XML tool. Subsequent post-processing of the converted EDI data is done through XQuery or XSLT, modeling a real world XML data integration application.

XSL-List

The XSL-List forum is a valuable learning resource for the Extensible Stylesheet Language (XSL), covering the XSL specification, XSL processor implementations, and XSL user questions. Get this free XSL resource delivered to your inbox today.

XML Code Folding

Stylus Studio's XML Editor features XML code folding, a powerful and intuitive way to maximize limited screen real-estate and help make sense of large XML files.

Technology Companies That Use Stylus Studio

Technology companies can't always handle every technology that they come across. That's why when it comes to XML, they look to Stylus Studio to guide them. Check out which top technology companies are looking to the future with Stylus Studio.

Stylus Most Wanted

 
Free Stylus Studio XML Training:
W3C Member