XSLT Extension

Introduction

Diff-X provides some static method which can be used in XSLT as extension functions.

Saxon

To use Diff-X as an XSLT extension, you need to ensure that saxon-dom.jar is included in your classpath as Diff-X will compare DOM nodes.

In your XSLT, declare the namespace as:

 <xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:diffx="java:com.topologi.diffx.Extension"
    extension-element-prefixes="diffx">

Diff-X can then be called within your XSLT as an extension function as:

 diffx:diff(node1, node2, whitespace_processing, text_granularity)"/>

With:

  • node1 the first node to compare (Node)
  • node2 the first node to compare (Node)
  • whitespace processing to indicate how white spaces should be processed, valid options are COMPARE, PRESERVE or IGNORE (xs:string)
  • text granularity to indicate the level of precision in text comparison, valid options are TEXT or WORD (xs:string)

 

For example, to compare two nodes ignoring whitespaces and detecting text differences at the word level, use:

 <xsl:copy-of select="diffx:diff(/node1/to/compare, /node2/to/compare, 'IGNORE', 'WORD')"/>

For more info on how to use saxon extension function, visit Saxonica's website: http://www.saxonica.com/documentation9.1/extensibility/functions.html

 

Created on , last edited on