1. Invisible XML in Saxon

The CoffeeSacks extension functions allow a stylesheet to load an Invisible XML grammar and process an input against it. Grammar processing can be expensive. To mitigate this cost, by default CoffeeSacks keeps a cache of parsed grammar.

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:

1date: s?, day, -s, month, (-s, year)? .
-s: -" "+ .
day: digit, digit? .
-digit: "0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9".
5month: "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="grammar" select="cs:grammar-uri('date.ixml')"/>
  <doc>
    <xsl:sequence select="cs:parse-string($grammar, '15 February 2022')"/>
10  </doc>
</xsl:template>
 
</xsl:stylesheet>

Returning:

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