Code Monkey home page Code Monkey logo

xmlspectrum's Introduction

XMLSpectrum

Syntax-highlighter for XQuery 3.0 , XSLT 3.0 and XPath 3.0 and XML

Why

  1. Many generic syntax-highlighters can't render XQuery or XPath 2.0/3.0 reliably, whether it is standalone or embedded in XML, such as XSLT, XSD, XProc, Schematron etc.

  2. The 'pretty-print' options of many XML editors can not align XML attributes and their contents properly. This omission is especially critical for the readability of XPath 2.0/3.0.

XMLSpectrum aims to remedy these problems.

What XMLSpectrum comprises a principal XSLT 2.0 stylesheet and supporting stylesheets designed specially to convert XQuery or XPath and any host XML code (such as XSLT) to HTML with syntax highlighting. There's also a simple GUI application XMLSpectrum-FX to provide a convenient front-end for the XSLT (designed for blogging editors).

Main Roles

  • Syntax highlighter
  • Code formatter
  • Code hyper-linker

Built-in language support

  • XQuery 1.0 - 3.0
  • XPath 1.0 - 3.0
  • XSLT 1.0 - 3.0
  • XSD 1.1
  • XProc
  • Schematron

Sample output for XSLT code:

Screenshot

Sample output for XQuery code:

Screenshot

Emphasis on accurate rendering of XQuery and XPath expressions, either within XSLT/XSD or standalone. By default, all formatting is preserved exactly as-is - with trim and formatting options

##Features

Syntax Highlighting:

  • Processes plain-text or XML-text (complete or otherwise)

  • Optionally processes xsl:include and xsl:import referenced XSLT

  • Uses standard XSLT 2.0 - no extensions required (tested on Saxon-HE)

  • Complete with 6 color themes including: Solarized light/dark, Tomorrow Night or Roboticket color themes - or define your own

  • Generates CSS file if required - or embeds CSS styling within content

  • Option to use the new Adobe Source Code Pro font

  • Extensible for any XML format containing embedded XPath

  • XQuery XPath Highlighting:

    • State machine for context-aware processing
    • All whitespace formatting preserved
    • Supports latest XPath/XQuery 3.0 additions
  • XML Highlighting

    • Supports fragments or complete XML - Target namespace prefix can be inferred from 1st element
    • Built-in XML parser (coded in XSLT) keeps all text, as-is
    • CDATA preserved intact and highlighted
    • Language identification (from namespace - if present) - CSS styled element/ancestor highlighting - on mouse hover
  • XSLT Highlighting

    • Scheme colors help separate instructions from expressions - Literal Result Elements have different coloring
    • XPath colored for AVTs or native XPath attributes
    • All formatting preserved
  • Other 'Host Language' Highlighting (built-in)

    • XSD 1.1
    • Schematron
    • XProc 1.0
    • Generic XML

Formatting:

  • Formatting including whitespace between attributes and within attribute contents preserved by default
  • XML content is shown exactly as in the source - including intact entity references and CDATA sections etc.

Formatting options - for use when original formatting requires correction

  • [Option] Indent
    • Indents XML proportional to the nesting level (Same as standard formatters)
    • Smart attribute formatting (advanced feature)
      • Aligned vertically with indentation consistent with the host element
      • Multi-line content vertically aligned with pre-existing indentation preserved
  • [Option] Auto-Trim
    • Smart trim of pre-existing indentation (normally combined with the indent option) - Records and re-establishes indentation for the following:
      • text nodes
      • xpath comments
      • xml comments
      • xpath expressions
  • [Option] Force-Newline
    • Inserts line-feeds to format XML elements - Preserves content of elements found with mixed-content

Cross-referencing:

Recursively processes all XSLT modules from a top-level stylesheet in a multi-file project

  • Creates top-level 'map' to all modules
    • Global members listed for each module
    • Map entries hyperlinked to the code definitions
    • Module entries hyperlinked to syntax-highlighted file
    • Global members sorted alphabetically by name
  • Adds hyperlinks in code for:
    • xsl:include and xsl:import hrefs
    • Global Parameters
    • Global Variables
    • Standard Functions
    • User-defined Functions
    • Named Templates
  • Clark-notation based linking to ensure integrity of links

##XMLSpectrum in use

###Command Line

Sample bash and doc scripts are included as a convenience in the app/shell-cmd directory. These scripts invoke the Saxon XSLT processor with the highlight-file.xsl stylesheet and perform basic file path resolving and checking on the input file (supplied as the first argument when calling the script) for the current directory - not the script or directory.

script description
xmlspec HTML syntax highlighting of XSLT/XML or XQuery
xslprint HTML syntax highlighting and TOC for multi-module XSLT project
xslformat reformatting of source for XSLT/XML - output is formatted XML

Examples:

1. xslformat.sh nolines.xml force-newline=yes
2. xmlspec.sh nolines.xml force-newline=yes color-theme=pg-light indent=2

###GUI

XMLSpectrum-FX - A simple Java app included in this repository (latest build at gui-project/xmlspectrum-fx-dist.zip). This provides a front-end useful for showcasing the XSLT, clipboard and drag and drop functionality make it useful in its own right for highlighting code snippets for blogging etc. Tested by pasting clipboard contents into WordPress and Blogger HTML text editors - (Blogger requires a surround div element with an overflow:auto style attribute.)

Screenshot

###Sample Output from XMLSpectrum transforms

demo output of Docbook XSLT 2.0 Project

demo output of DITA XSLT Project

XMLSpectrum Project - run on itself

Transformed web page with embedded code samples

W3C XQuery 3.0 Specification Samples

Syntax-highlighted XProc file

Included XSLT solutions

The xmlspectrum.xsl and xq-spectrum.xsl stylesheets are intended for use by other stylesheets that import these and exploit the main functions: render, show-xquery and indent:

  • highlight-inline.xsl - transforms XHTML file containing descriptive text and XSLT, XSD or XPath code examples
  • highlight-file.xsl - transforms files containing XSLT,XSD or XPath - can process multi-file XSLT projects

Solarized Dark theme:

Screenshot

Tomorrow-Night theme + Source Code Pro font:

Screenshot

##Usage

For usage instructions, see xmlspectrum/app/xsl/readme

xmlspectrum's People

Contributors

maxtoroq avatar pgfearo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xmlspectrum's Issues

any plans to support xquery ?

I plan to revamp look and feel of xquerydoc and was looking around for a better source code highlighter ... how does it handle xquery these days ?

XQuery 3.0 Function Annotations

Hi Phil,

I was wondering if it may be possible to support Function Annotations?

declare
  %my-ns:my-local("my value")
  %xdmp:single-without-arguments
  %xdmp:four-data-types("string", true, false, 123, 123.456)
function local:process($var as xs:string)
{
  1 to 10
};

Regards,

Charles

JavaFX rendering issues?

Hi,
I just tried this on a win 8.1 machine with java version

java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

Things dont look right
2014-07-10 22_22_52-greenshot
And there is a character set issue?
2014-07-10 22_24_37-greenshot

http://maxtoroq.github.io/xslt-hl/ works fine for me :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.