Class Extension

java.lang.Object
com.topologi.diffx.Extension

public final class Extension extends Object
To use Diff-X as an XSLT extension.

In Saxon, declare the namespace as:


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

Diff-X can be called within XSLT with:


 <xsl:copy-of select="diffx:diff(/node1/to/compare, /node2/to/compare, 'IGNORE', 'TEXT')"/>
 
Note: the method signatures requires DOM arguments, include the Saxon-DOM jar on your classpath to use this extension function with Saxon.
Version:
18 May 2010
  • Field Details

    • BUILDERS

      private static final Map<String,String> BUILDERS
      Maps the DOM builder factory to use with the given DOM package.

      This is because some XSLT processors will only accept certain types DOM objects.

  • Constructor Details

    • Extension

      public Extension()
  • Method Details

    • diff

      public static Node diff(Node xml1, Node xml2, String whitespace, String granularity) throws DiffXException, IOException
      Compares the two specified Nodes and returns the diff as a node.

      Only the first node in the node list is sequenced.

      Parameters:
      xml1 - The first XML node to compare.
      xml2 - The second XML node to compare.
      whitespace - The white space processing (a valid WhiteSpaceProcessing value).
      granularity - The text granularity (a valid TextGranularity value).
      Throws:
      DiffXException - Should a Diff-X exception occur.
      IOException - Should an I/O exception occur.
    • diff

      private static void diff(EventSequence seq1, EventSequence seq2, Writer out, DiffXConfig config) throws DiffXException, IOException
      Compares the two specified xml files and prints the diff onto the given writer.
      Parameters:
      seq1 - The first XML reader to compare.
      seq2 - The first XML reader to compare.
      out - Where the output goes.
      config - The DiffX configuration to use.
      Throws:
      DiffXException - Should a Diff-X exception occur.
      IOException - Should an I/O exception occur.
    • toConfig

      private static DiffXConfig toConfig(String whitespace, String granularity)
      Returns the Diff-X config for the specified argument as String.
      Parameters:
      whitespace - A valid white space processing value.
      granularity - A valid text granularity value.
      Returns:
      the Diff-X config for the specified arguments as String.
    • toNode

      private static Node toNode(String xml, DiffXConfig config, String factory) throws IOException, ParserConfigurationException, SAXException
      Returns a node for the specified string value.
      Parameters:
      xml - The XML to parse.
      config - The DiffX configuration to use.
      factory - The class name of the DOM builder factory.
      Returns:
      the corresponding document node.
      Throws:
      IOException
      ParserConfigurationException
      SAXException
    • getFactoryClass

      private static String getFactoryClass(Node xml1, Node xml2)
      Returns the factory class to use based on the given NodeLists.
      Parameters:
      xml1 - the first node list.
      xml2 - the second node list.