Extending XSLT with Java and C#



Similar documents
Application Development With Data Studio

Authoring for System Center 2012 Operations Manager

DataDirect XQuery Technical Overview

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

Tutorial 5: Developing Java applications

MarkLogic Server. Connector for SharePoint Administrator s Guide. MarkLogic 8 February, 2015

Course Information Course Number: IWT 1229 Course Name: Web Development and Design Foundation

Cleo Communications. CUEScript Training

Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer

CRM Setup Factory Installer V 3.0 Developers Guide

Stylus Studio 2010 XML Feature Comparison Matrix

Building and Using Web Services With JDeveloper 11g

Developing In Eclipse, with ADT

Visual Basic. murach's TRAINING & REFERENCE

How To Use X Query For Data Collection

BPM Scheduling with Job Scheduler

T-CONNECT EDI VIEWER. Installation and User Guide 12/16/2014 WE BUILD SOFTWARE THAT HELPS OUR CLIENTS GROW DOCUMENT CREATED BY:

Creating XML Report Web Services

EMC Documentum Composer

Code Estimation Tools Directions for a Services Engagement

JBoss SOAP Web Services User Guide. Version: M5

Listeners. Formats. Free Form. Formatted

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Creating Web Services Applications with IntelliJ IDEA

Database Application Developer Tools Using Static Analysis and Dynamic Profiling

INFOPATH FORMS FOR OUTLOOK, SHAREPOINT, OR THE WEB

ID TECH UniMag Android SDK User Manual

SharePoint Integration Framework Developers Cookbook

WIRIS quizzes web services Getting started with PHP and Java

Tutorial Build a simple IBM Rational Publishing Engine (RPE) template for IBM Rational DOORS

Beyond The Web Drupal Meets The Desktop (And Mobile) Justin Miller Code Sorcery Workshop, LLC

Accessing Data with ADOBE FLEX 4.6

Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB)

Source Code Translation

Sonatype CLM Enforcement Points - Continuous Integration (CI) Sonatype CLM Enforcement Points - Continuous Integration (CI)

Terms and Definitions for CMS Administrators, Architects, and Developers

MICROSOFT EXAM QUESTIONS & ANSWERS MICROSOFT EXAM QUESTIONS & ANSWERS

Cache Configuration Reference

Oracle Service Bus Examples and Tutorials

Oracle SQL Developer for Database Developers. An Oracle White Paper September 2008

Deploying Microsoft Operations Manager with the BIG-IP system and icontrol

JBoss Portlet Container. User Guide. Release 2.0

... Introduction... 17

An Oracle White Paper May Creating Custom PDF Reports with Oracle Application Express and the APEX Listener

Web services with WebSphere Studio: Deploy and publish

Xtreeme Search Engine Studio Help Xtreeme

Introduction to NaviGenie SDK Client API for Android

Creating Form Rendering ASP.NET Applications

DEVELOPING CONTRACT - DRIVEN WEB SERVICES USING JDEVELOPER. The purpose of this tutorial is to develop a java web service using a top-down approach.

SAML v1.1 for.net Developer Guide

Firewall Builder Architecture Overview

Windows PowerShell Cookbook

To install Multifront you need to have familiarity with Internet Information Services (IIS), Microsoft.NET Framework and SQL Server 2008.

C#5.0 IN A NUTSHELL. Joseph O'REILLY. Albahari and Ben Albahari. Fifth Edition. Tokyo. Sebastopol. Beijing. Cambridge. Koln.

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

Homework 9 Android App for Weather Forecast

DataDirect XQuery and the Insurance Industry

Installation Documentation Smartsite ixperion 1.3

<Insert Picture Here> Michael Hichwa VP Database Development Tools Stuttgart September 18, 2007 Hamburg September 20, 2007

VOC Documentation. Release 0.1. Russell Keith-Magee

For Introduction to Java Programming, 5E By Y. Daniel Liang

Implementing SQI via SOAP Web-Services

Hypercosm. Studio.

Getting Started with the Ed-Fi ODS and Ed-Fi ODS API

business transaction information management

Schematron Validation and Guidance

Desktop, Web and Mobile Testing Tutorials

SelectSurvey.NET Developers Manual


ConvincingMail.com Marketing Solution Manual. Contents

Running a Program on an AVD

Protect, License and Sell Xojo Apps

Computing Concepts with Java Essentials

How To Create A Website Template On Sitefinity

Oracle9i Application Server: Options for Running Active Server Pages. An Oracle White Paper July 2001

Creating a Java application using Perfect Developer and the Java Develo...

FileMaker Server 9. Custom Web Publishing with PHP

WebSpy Vantage Ultimate 2.2 Web Module Administrators Guide

Crystal Reports for Borland JBuilder

A standards-based approach to application integration

QML and JavaScript for Native App Development

CrownPeak Playbook CrownPeak Hosting with PHP

Introduction to XML Applications

Sitecore InDesign Connector 1.1

Oracle Universal Content Management

Web Services API Developer Guide

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Building A Very Simple Website

ibolt V3.2 Release Notes

Getting Started Guide

NetBeans IDE Field Guide

Custom Tasks for SAS. Enterprise Guide Using Microsoft.NET. Chris Hemedinger SAS. Press

Markup Languages and Semistructured Data - SS 02

IBM VisualAge for Java,Version3.5. Remote Access to Tool API


Integration Overview. Web Services and Single Sign On

This means that any user from the testing domain can now logon to Cognos 8 (and therefore Controller 8 etc.).

How To Install An Aneka Cloud On A Windows 7 Computer (For Free)

EPIC - User s Guide i. EPIC - User s Guide

Transcription:

Extending XSLT with Java and C# The world is not perfect. If it were, all data you have to process would be in XML and the only transformation language you would have to learn would XSLT. Because the world is not perfect, sometimes you have to find ways to bridge different systems that were not designed to work together. The most popular XSLT processors have been designed, from the very first release, to take advantage of the framework on which they run; for example Apache Xalan-J and Saxon allow calling Java functions. In this article, we will explore a variety of techniques for invoking native code from XSLT to extend the language beyond its capabilities. The first example demonstrates how to leverage the Date and Time formatting capabilities available in the Java platform. Imagine you have a list of dates in an XML file that you have to display in a HTML page using different formats. The following screenshot shows a simple XML file with three repeating elements called date, each has three attributes: year, month and day.

A separate XML document has the date formats. Each element entry has an attribute format with the picture string which describes how and which part of the date should be displayed.

Our goal is to merge the information from the two XML documents into a simple HTML page which will display each date in multiple formats. XSLT 1.0 lacks date and time formatting functions but, Java provides two classes: java.util.calendar and java.text.simpledateformat, which solve our problem. We just need to create a Java class with a single public static method that will be called from our XSLT transformation. In the following screenshot, we see the Stylus Studio Java extension editor which features syntax coloring, background syntax checking and integrated Java compiler invocation.

When designing Java extension functions for XSLT, it is important to remember that the function parameter type has to be compatible with the processor type mapping. Apache XalanJ defines the following type mapping between XSLT and Java. XSLT Type Node-Set String Boolean Number Result Tree Fragment Java Type org.w3c.dom.traversal.nodeiterator java.lang.string java.lang.boolean java.lang.double org.w3c.dom.documentfragment Extension function support is implemented differently on each XSLT processor which makes it difficult to port XSLT code from one processor to another. In order to run a transformation that makes use of Java code, you have to ensure that the compiled Java code (.class) is reachable from the CLASSPATH. This is a pesky setting which requires changing the

environment variable called CLASSPATH. Fortunately Stylus Studio provides a flexible mechanism to include the Java compiled code (directories or Jar files) at the project level and, if the code is located under the project, Stylus Studio saves the path using a relative form. Therefore, you can move your project to a different location without fear of breaking the link between your XSLT and your Java code. In the following screenshot, we see how to bind a Java class using XalanJ. The Xalan Java namespace declaration is at line 4, the function invocation is at line 19. Notice that the function name is formed with the prefix java: then the full Java class name the. and the function name. The Preview shows the transformation result.

Running the same transformation with Saxon requires a small change. The Java class binding is at line 4; the namespace URI is composed of the prefix java: and the full Java class name. The function invocation uses the namespace prefix date: and the Java method name. The same result is generated in the Preview window.

One major advantage in testing the code with Saxon in Stylus Studio is the ability to run the transformation in the XSLT debugger and step into the Java code to debug the Java extension, which is unique to Stylus Studio. In the following screenshot we see the execution suspended inside the extension function printdate. The Call-stack window shows from which XSLT template we came in and which parameter values were passed. The Variables window shows all variables in scope with their values. This is an unparalleled experience for the developers who usually have to write hundreds of trace messages in a log file in order to debug their code. A side note: notice the second item from the top, in the Call-stack window. The new Saxon Just in Time XSLT to Java compiler generates Java code on the fly!

Stylus Studio mapping tool also provides full support for Java extension functions. In the following screenshot you see how to register a Java extension class, browsing the project CLASSPATH.

Once a Java extension class is registered, all of its functions are exposed. To add a new java function call, simply click on the Java Functions menu item.

With a few additional links, the mapping is complete. The XSLT visual mapping tool allows XSLT developers to take advantage of Java libraries developed by others without the need to know the underlying technical details.

Java is not the only language that can be employed for designing extension functions. If you are developing on Microsoft.NET framework and make use of XslCompiledTransform XSLT processor, you have access to the entire framework API. The following screenshot shows how to implement the date formatter in C# but we could have used JScript as well. The inline code embedded in the XSLT transformation is compiled into MSIL (Microsoft Intermediate Language) by the Just in Time C# compiler. Inline extension functions have several logistic benefits: you don t need to compile a separate module and you don t need to maintain your logic in a different file.

If you need to debug such a transformation, Stylus Studio comes to the rescue Just switch the processor to XslTransform in the XSLT editor scenario dialog and you will be able to debug your code step by step.

In the following screenshot you see the execution suspended inside XSLT match template date. The Call-stack window shows the current stack and the variable window shows all variables in scope with their values and XSLT context which represent the XML node currently processed.

The msxsl:script block allows you to import third party.net libraries which open the door to virtually infinite possibilities. In the following XSLT code fragment, an extension function called fromedi makes use of XML Converters for.net to parse an EDI file and to return an instance of XPathNavigator which can be manipulated in the XSLT as an XML node. <msxsl:script implements-prefix='ut' language='c#'> <msxsl:assembly href="c:\program Files (x86)\xml Converters for.net\bin\xmlconverters.dll"/> <msxsl:using namespace="ddtek.xmlconverter" /> <msxsl:using namespace="system.io" /> <![CDATA[ public XPathNavigator fromedi(string edipath) { ConverterFactory factory = new ConverterFactory(); string url = "converter:edi?" + edipath; XmlReaderSettings settings = new XmlReaderSettings(); settings.xmlresolver = factory.createresolver(); XmlReader reader = XmlReader.Create(url, settings); XPathDocument doc = new XPathDocument(reader); return doc.createnavigator(); } ]]> </msxsl:script> <xsl:template match="/"> <xsl:variable name="edixml" select="ut:fromedi($edi)"/>

We hope you enjoyed reading this article. If you have any questions, do not hesitate to contact us. You can download the Project Zip file by clicking here. - Stylus Studio Team Technical Support Follow us on Twitter Connect on Facebook