Chapter 1Invisible XML in Saxon

The CoffeeSacks extension functions allow a stylesheet to load an Invisible XML grammar and process an input against it.

The class org.nineml.coffeesacks.RegisterCoffeeSacks is suitable for registering the extension functions to a Saxon HE processor.

All of the functions are in the namespace http://nineml.com/ns/coffeesacks which is taken to be bound to the cs: namespace prefix in this document.

Given an Invisible XML grammar for dates in date.ixml:

1 |date: s?, day, -s, month, (-s, year)? .
  |-s: -" "+ .
  |day: digit, digit? .
  |-digit: "0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9".
5 |month: "January"; "February"; "March"; "April";
  |       "May"; "June"; "July"; "August";
  |       "September"; "October"; "November"; "December".
  |year: (digit, digit)?, digit, digit .

A stylesheet like the following will parse a string against that grammar and return the result:

 1 |<?xml version="1.0" encoding="utf-8"?>
   |<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   |                xmlns:cs="http://nineml.com/ns/coffeesacks"
   |                exclude-result-prefixes="#all"
 5 |                version="3.0">
   | 
   |<xsl:output method="xml" encoding="utf-8" indent="yes"/>
   | 
   |<xsl:template match="/">
10 |  <xsl:variable name="parser" select="cs:load-grammar('date.ixml')"/>
   |  <doc>
   |    <xsl:sequence select="$parser('15 February 2022')"/>
   |  </doc>
   |</xsl:template>
15 | 
   |</xsl:stylesheet>

Returning:

1 |<doc>
  |   <date>
  |      <day>15</day>
  |      <month>February</month>
5 |      <year>2022</year>
  |   </date>
  |</doc>