Share

XSLT syntax highlighting

The forum address has changed, you have been automatically redirected. Please update any bookmarks to use the new URL.

Subscribe

Version for saxon 8 ?

You are viewing a single message from this topic. View all messages.

  1. 2006-11-06 14:43:01 UTC
    No, it is quite easy to make it work with saxon 8 (actually it was originally writen for saxon8 and xalan and later backported to saxon6):

    1) You need ConnectorSaxon8.java:

    package net.sf.xslthl;

    import java.io.*;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;

    public class ConnectorSaxon8 {

    private static Node blockToDomNode(Block b, Document doc, Config config) {
    Node textNode = doc.createTextNode(b.getText());
    if (b.isStyled()) {
    Element elem = doc.createElementNS(config.uri, config.prefix + ":" + ((StyledBlock)b).getStyle());
    elem.appendChild(textNode);
    return elem;
    }
    return textNode;
    }

    protected static NodeList highlight(String source, MainHighlighter hl, Config config) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = dbf.newDocumentBuilder();
    Document doc = builder.newDocument();
    Element fragment = doc.createElement("container");
    doc.appendChild(fragment);

    List<Block> l = hl.highlight(source);
    for (Block b : l) {
    fragment.appendChild(blockToDomNode(b, doc, config));
    }

    return fragment.getChildNodes();
    }

    public static NodeList highlight(String hlCode, String source) throws Exception {
    try {
    Config c = Config.getInstance();
    MainHighlighter hl = c.getMainHighlighter(hlCode);
    return highlight(source, hl, c);
    }
    catch (Exception e) {
    e.printStackTrace();
    return null;
    }
    }

    }

    2) compile it with saxon8.jar on path

    3) In output_html.xsl you have to replace all lines like this one:
    <xsl:variable name='pass1' select="hl:highlight('java', $source)" />
    with:
    <xsl:variable name='pass1'>
    <xsl:copy-of select="hl:highlight('java', $source)" />
    </xsl:variable>

    4) running it like
    java -cp ..\saxon8\saxon8.jar;..\saxon8\saxon8-dom.jar;classes net.sf.saxon.Transform -o example-java-to-html.html "example_sources/example-java.xml" xsl/example-java-to-html.xsl

    (note that you must have there also saxon8-dom.jar, not just saxon8.jar)
< Previous | 1 | Next >

Add a Reply

You may use standard BBCode tags in your post.

Monitor this

Log in to monitor this topic. Not registered? Create an account to receive email updates when replies are posted to this topic. If you do not log in or register, your reply will be added anonymously.