[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Re: XSLT-driven syntax highlighting for XPath 2.0, XSLT 2.0 and XSD 1.1

Subject: Re: [xsl] Re: XSLT-driven syntax highlighting for XPath 2.0, XSLT 2.0 and XSD 1.1
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 30 Nov 2012 05:18:10 -0800

That is impressive work, Phil,

I wonder if the XML parser has some limitations (such as processing
DTD's or XML Schemas -- with all their features) on which the source
XML document is based?

I will need to spend some time to play eith this syntax hi-lighter
(BTW, we need a better name for this kind of tools) but an apparent
use-case I have is a special hi-lighting of variables/parameters. As
we all too-well know one of the most frequent and most difficult to
detect programming error is failing to precede a (what must be a)
variable reference with the '$' character. I would like any such
occurence to be hi-lighted in bold red, and in addition, even
flashing. Just implementing this will save many hours of confusion to
us all.

Impressive work.


On Fri, Nov 30, 2012 at 2:31 AM, Philip Fearon <pgfearo@xxxxxxxxxxxxxx> wrote:
> Excellent, it would be good to see this.
> A minor change would be required to identify partial code examples by
> something other than the namespace where this is omitted from examples
> for brevity sake - currently, if the XML parse to extract the
> namespace fails, the input is assumed to be plain-text XPath.
> The 'xsl' prefix used for the XSLT namespace would also need to be
> supplied somehow.
> Phil
> On Fri, Nov 30, 2012 at 9:39 AM, Philip Fearon <pgfearo@xxxxxxxxxxxxxx> wrote:
>> I frequently need to publish documentation in HTML form that has code samples
>> which include XPath 2.0 expressions, either standalone or embedded in XSLT 2.0.
>> But has anyone else noticed that there aren't many syntax highlighters
>> for standalone
>> or XML-embedded XPath on the web?
>> To improve this choice, I've developed an XSLT 2.0 stylesheet that's a
>> syntax highlighter
>> specially for XPath 2.0, XSLT 2.0, XSD 1.1 (the assert element) and
>> also suitable for
>> generic XML. The input to the stylesheet (specfied in an XSL
>> parameter) is either XML
>> or plain-text, the output is an HTML document and a CSS file.
>> I'm sharing this in the hope that others may also find it useful. Note
>> that this is not a
>> 'pretty-print' formatter, it is assumed that whitespace formatting is
>> in-place and this is
>> all preserved in the output (including inter/intra-attribute whitespace etc.).
>> One main concern with embedded languages (like XPath within XSLT) is
>> not to overwhelm
>> the reader with highlighted code colors. To alleviate this I've used
>> the Solarized[1] color
>> theme which has 8 highlight colors (+ 8 base colors) of relatively low
>> contrast. Cooler
>> colors are used for XML-based syntax and warmer colors for the XPath.
>> There's some
>> crossover though: for example, to show that an xsl:function 'name'
>> attribute is referenced
>> from XPath, a warmer color is used.
>> Features List:
>> --------------
>> - Open source - maintained on GitHub
>> - Processes plain-text or XML files
>> - Identifies XML coloring scheme from the root namespace (if XML)
>> - Just 1300 or so lines of XSLT in one file - no dependencies
>> - Standard XSLT 2.0. No extensions required (developed/tested on
>> Saxon-HE and Saxon-CE)
>> - Uses 'Solarized' color theme
>> - Light or dark color themes
>> - Generates the required CSS file also - depending on theme specified
>> - XPath 2.0 Highlighting:
>>           - Supports XPath Comments
>>           - All whitespace formatting preserved
>>           - No dependency on reserved keywords
>>           - Standalone files supported - or embedded in XML
>>           - Designed to be extensible to support XPath 3.0
>> - XML Highlighting
>>           - Built-in XML parser (coded in XSLT) keeps all text, as-is
>>           - CDATA preserved intact and highlighted
>> - XSLT 2.0 Highlighting
>>           - Scheme colors help separate instructions from expressions
>>           - Literal Result Elements have different coloring
>>           - AVTs or native XPath attributes supported
>>           - All whitespace formatting preserved
>> - XSD 1.1 Highlighting
>>            - Element and Attribute definition elements highlighted
>>            - XPath coloring for *test* attribute in *assert* element
>> Links:
>> Sample screenshot of XSLT 2.0 using dark color theme:
>> http://qutoric.com/xslt/xmlspectrum/images/xsl-dark.PNG
>> The stylesheet 'xmlspectrum.xsl' is on the GitHub project site along
>> with samples etc. at:
>> https://github.com/pgfearo/xmlspectrum
>> Acknowledgements:
>> [1 Solarized] http://ethanschoonover.com/solarized
>> As ever, any feedback on color themes, missing features, issues etc
>> would be greatly appreciated. Details on other XSLT stylesheets that
>> do the same thing that would also
>> be useful to know.
>> Many thanks,
>> Phil Fearon
>> http://qutoric.com

Dimitre Novatchev
Truly great madness cannot be achieved without significant intelligence.
To invent, you need a good imagination and a pile of junk
Never fight an inanimate object
To avoid situations in which you might make mistakes may be the
biggest mistake of all
Quality means doing it right when no one is looking.
You've achieved success in your field when you don't know whether what
you're doing is work or play
Facts do not cease to exist because they are ignored.
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
I finally figured out the only reason to be alive is to enjoy it.

Current Thread