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 dates.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 |<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   |                xmlns:cs="http://nineml.com/ns/coffeesacks"
   |                exclude-result-prefixes="#all"
   |                version="3.0">
 5 | 
   |<xsl:template name="xsl:initial-template">
   |  <xsl:variable name="parser"
   |                select="cs:load-grammar('date.ixml')"/>
   |  <doc>
10 |    <xsl:sequence select="$parser('15 February 2022')"/>
   |  </doc>
   |</xsl:template>
   | 
   |</xsl:stylesheet>

Returning:

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