html5/markup/rng-incelim-1.2 clean.xsl,NONE,1.1 elim.xsl,NONE,1.1 inc.xsl,NONE,1.1 incelim,NONE,1.1 incelim.xsl,NONE,1.1 license.txt,NONE,1.1 readme.dbx,NONE,1.1 readme.txt,NONE,1.1 saxon-6.5.3.diff,NONE,1.1 strip.xsl,NONE,1.1

Update of /sources/public/html5/markup/rng-incelim-1.2
In directory hutz:/tmp/cvs-serv30887

Added Files:
	clean.xsl elim.xsl inc.xsl incelim incelim.xsl license.txt 
	readme.dbx readme.txt saxon-6.5.3.diff strip.xsl 
Log Message:
initial add


--- NEW FILE: strip.xsl ---
<?xml version="1.0"?>
<!-- $Id: strip.xsl,v 1.1 2009/07/29 08:32:51 mike Exp $ -->

<xsl:transform
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:rng="http://relaxng.org/ns/structure/1.0"
	xmlns="http://relaxng.org/ns/structure/1.0"
	version="1.0">
	
  <xsl:key name="simple"
    match="rng:define[count(rng:text|rng:empty|rng:notAllowed)=count(*)]"
    use="@name"/>

  <xsl:key name="complex"
    match="rng:define[count(rng:text|rng:empty|rng:notAllowed)!=count(*)]"
    use="@name"/>

  <xsl:template match="/">
    <xsl:apply-templates mode="strip"/>
  </xsl:template>

  <xsl:template mode="strip" match="rng:ref">
    <xsl:variable name="simple" select="key('simple',@name)"/>
    <xsl:variable name="complex" select="key('complex',@name)"/>
    <xsl:choose>
      <xsl:when test="count($simple)=1 and not($complex)">
	<xsl:apply-templates mode="strip" select="$simple/*"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy>
	  <xsl:apply-templates mode="strip" select="*|@*|text()|comment()"/>
	</xsl:copy>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template mode="strip" match="*|@*|text()|comment()">
    <xsl:copy>
      <xsl:apply-templates mode="strip" select="*|@*|text()|comment()"/>
    </xsl:copy>
  </xsl:template>

</xsl:transform>

--- NEW FILE: elim.xsl ---
<?xml version="1.0"?>
<!-- $Id: elim.xsl,v 1.1 2009/07/29 08:32:50 mike Exp $ -->

<xsl:transform
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:rng="http://relaxng.org/ns/structure/1.0"
	xmlns="http://relaxng.org/ns/structure/1.0"
	exclude-result-prefixes="rng"
	version="1.0">

  <xsl:template match="/">
    <xsl:apply-templates mode="elim"/>
  </xsl:template>

  <xsl:template mode="elim" match="rng:include">
    <rng:div>
      <xsl:apply-templates mode="elim" select="*|@*|text()|comment()"/>
    </rng:div>
  </xsl:template>

  <xsl:template mode="elim" match="rng:define">
    <xsl:call-template name="cp-unless-ovr">
      <xsl:with-param name="incelim" select="ancestor::rng:include[1]"/>
      <xsl:with-param name="define" select="."/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="cp-unless-ovr">
    <xsl:param name="incelim"/>
    <xsl:param name="define"/>
    <xsl:choose>
      <xsl:when test="$incelim
          and generate-id($define/ancestor::rng:grammar[1])
	    = generate-id($incelim/ancestor::rng:grammar[1])">

 	<xsl:if test="not(
           $incelim/preceding-sibling::*/descendant-or-self::rng:define[
	     @name=$define/@name
	     and generate-id(ancestor::rng:grammar[1])
	       = generate-id($incelim/ancestor::rng:grammar[1])])">
	  <xsl:call-template name="cp-unless-ovr">
	    <xsl:with-param name="incelim"
	      select="$incelim/ancestor::rng:include[1]"/>
	    <xsl:with-param name="define" select="$define"/>
	  </xsl:call-template>
	</xsl:if>
      </xsl:when>

      <xsl:otherwise>
        <rng:define>
	  <xsl:for-each select="$define">
	    <xsl:apply-templates mode="elim" select="*|@*|text()|comment()"/>
	  </xsl:for-each>
	</rng:define>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template mode="elim" match="*|@*|text()|comment()">
    <xsl:copy>
  	<xsl:apply-templates mode="elim" select="*|@*|text()|comment()"/>
    </xsl:copy>
  </xsl:template>

</xsl:transform>

--- NEW FILE: saxon-6.5.3.diff ---
--- com/icl/saxon/expr/FragmentValue.java.orig	Sun Jan 18 19:33:32 2004
+++ com/icl/saxon/expr/FragmentValue.java	Sun Jan 18 19:34:39 2004
@@ -20,7 +20,7 @@
 
     private char[] buffer = new char[4096];
     private int used = 0;
-    private Vector events = new Vector(20, 20);
+    private Vector events = new Vector(20/*, 20*/); /* events must expand exponentially, not linearly, otherwise exsl:node-set() cannot be used efficiently */
     private String baseURI = null;
     private FragmentEmitter emitter = new FragmentEmitter();
     private Controller controller;

--- NEW FILE: readme.dbx ---
<?xml version="1.0"?>
<!-- $Id: readme.dbx,v 1.1 2009/07/29 08:32:50 mike Exp $ -->
<article>

  <title>incelim &#x2014; Relax NG Splicer</title>
  <subtitle>Version 1</subtitle>

  <abstract>
  <para>
   incelim takes a Relax NG grammar in XML syntax, expands all
   includes and externalRefs, and optionally replaces references
   to text, empty, or notAllowed with the patterns. The result is
   a 'compiled' schema convenient for distribution.
  </para> 
  </abstract>

  <para>
    The package includes stylesheets for each of the transformation
    steps, and two kinds of glue: XSLT stylesheet incelim.xsl, which
    chains the transformations using exsl:node-set(), and a shell
    script, incelim, which applies each of the stylesheets to the 
    serialized result of the previous one.
  </para>
  
  <section><title>Package Contents</title>

  <variablelist>
    <varlistentry>
      <term>inc.xsl</term>
      <listitem><para>
        literally inserts contents of included files (and externalRefs);
      </para></listitem>
    </varlistentry>
    <varlistentry>
      <term>elim.xsl</term>
      <listitem><para>removes overriden defines;
      </para></listitem>
    </varlistentry>
    <varlistentry>
      <term>strip.xsl</term>
      <listitem><para>splices references to single parameterless patterns
        (text,empty,notAllowed);
      </para></listitem>
    </varlistentry>
    <varlistentry>
      <term>clean.xsl</term>
      <listitem><para>filters out empty divs and unreferenced defines;
      </para></listitem>
    </varlistentry>
    <varlistentry>
      <term>incelim.xsl</term>
      <listitem><para>XSLT glue to chain the transformations;
      </para></listitem>
    </varlistentry>
    <varlistentry>
      <term>incelim</term>
      <listitem><para>(ash or bash) shell script to run each of the
      transformations in order;
      </para></listitem>
    </varlistentry>
    <varlistentry>
      <term>saxon-6.5.3.diff</term>
      <listitem><para>performance patch for SAXON 6.5.3;
      </para></listitem>
    </varlistentry>
    <varlistentry>
      <term>readme.txt, readme.dbx</term>
      <listitem><para>brief description in plain text and DocBook XML formats;
      </para></listitem>
    </varlistentry>
     <varlistentry>
      <term>license.txt</term>
      <listitem><para>the license.
      </para></listitem>
    </varlistentry>
 </variablelist>
  </section>

  <section><title>Invocation</title>
  <para>For the XSLT glue, the arguments are the source schema and
  the stylesheet. Parameter <varname>rinses</varname> specifies
  the number of times to apply strip/clean phase (it should be recursive,
  but it would be too complex for XSLT to stop timely). 1 is the default,
  more than 3 does not make sense in most practical cases.
  </para>

  <note>
    <itemizedlist>
    <listitem><para>
    xsltproc compiled against libxml 20604, libxslt 10102 and libexslt 802
    and earlier versions cannot be used with this stylesheets due to bugs
    in implementation of exsl:node-set();
    </para></listitem>

    <listitem><para>
    SAXON 6.5.[23] and jd.xslt 1.5.5 are slow, a patch for SAXON 6.5.3 that
    makes it fast is included in the distribution (saxon-6.5.3.diff).
    </para></listitem>
    </itemizedlist>
  </note>


  <para>The shell script takes a list of schema files and puts the
  result for each <filename>schema.rng</filename> into
  <filename>schema-compiled.rng</filename>. Additionally,the following
  command-line options are accepted:
  </para>

  <variablelist>
  <varlistentry>
    <term><option>-nnn</option></term>
    <listitem><para>number of strip/clean passes (default is <option>-1</option>)
    </para></listitem>
  </varlistentry>
  <varlistentry>
    <term><option>-processor</option></term>
    <listitem><para>XSLT processor to use, default is
    <option>-saxon</option>, other options are xt, jd.xslt, xalan,
    4xslt, xsltproc
    </para></listitem>
  </varlistentry>
  </variablelist>
<para>
  Environment variable <varname>INCELIM</varname> should point to the
  directory containing XSLT scripts, default is
  <filename>/usr/local/lib/incelim</filename>.  Temporary files are
  created in a directory pointed to by environment variable
  <varname>TMPDIR</varname>, <filename>/tmp</filename> by default.
</para>
</section>

<section>
<title>Aknowledgements</title>
<para>I would like to thank Sebastian Rahtz for the idea, inspiration, sample
stylesheet using exsl:node-set(),  and testing of the program.
</para>
</section>

<section><title>Terms and Conditions</title>
<para>This software is distributed under BSD license. The details
are in <filename>license.txt</filename>.
</para>
</section>

<section><title>News and updates</title>
<para>
Visit <ulink url="http://davidashen.net/">http://davidashen.net/</ulink>.
</para>
</section>

</article>

--- NEW FILE: incelim ---
#!/bin/sh

# $Id: incelim,v 1.1 2009/07/29 08:32:50 mike Exp $

if [ $# -eq 0 ]
then
  cat <<USAGE
incelim 1.0

usage:
	incelim [-nnn] [-processor] schema.rng ...
where
	-nnn is number of strip/clean passes (default is -1)
	-processor is XSLT processor to use, default is -saxon,
	 other options are xt, jd.xslt, xalan, 4xslt, xsltproc 

output for
	schema.rng
is in
	schema-compiled.rng
	
Environment variable INCELIM should point to the directory
containing XSLT scripts, default is /usr/local/lib/incelim.

Temporary files are created in a directory pointed to 
by environment variable TMPDIR, /tmp by default.
USAGE
exit 1
fi

INCELIM=${INCELIM:-/usr/local/lib/incelim}
TMPDIR=${TMPDIR:-/tmp}
rinses=1
proc=saxon

options=1
while [ $options -eq 1 ]
do
  case $1 in
     -[0-9]) rinses=`echo $1|sed s/^-//` ; shift ;;
     -xt|-saxon|-jd.xslt|-xalan|-xsltproc|-4xslt) proc=`echo $1|sed s/^-//` ; shift ;;
     -*) echo "unknown option $1" ; exit 1 ;;
     *) options=0 ;;
  esac
done

inc=${TMPDIR}/incelim.inc.$$
str=${TMPDIR}/incelim.str.$$

rmtmp() {
 rm -f $inc $str
}

intr() {
  echo "incelim: interrupted" >&2
  rmtmp
  exit 1
}

errs() {
  echo "incelim: exiting on errors" >&2
  rmtmp
  exit 1
}

xslt() {
  xml=$1
  xsl=${INCELIM}/$2
  res=$3
  case $proc in
    xt) java com.jclark.xsl.sax.Driver $xml $xsl $res ;;
    saxon) java com.icl.saxon.StyleSheet -o $res $xml $xsl ;;
    jd.xslt) java jd.xml.xslt.Stylesheet -out $res $xml $xsl ;;
    xalan) java org.apache.xalan.xslt.Process -IN $xml -XSL $xsl -OUT $res ;;
    4xslt) 4xslt -o $res $xml $xsl ;;
    xsltproc) xsltproc -o $res $xsl $xml ;;
  esac
  if [ $? -ne 0 ]; then errs; fi
}

trap intr HUP INT TERM

for src in $*
do
  tgt=`echo $src|sed 's/\.rng/\-compiled\.rng/'`
  xslt $src inc.xsl $inc
  xslt $inc elim.xsl $tgt
  i=$rinses
  while [ $i -ne 0 ]
  do
    xslt $tgt strip.xsl $str
    xslt $str clean.xsl $tgt
    i=$(($i-1))
  done
done

rmtmp

--- NEW FILE: clean.xsl ---
<?xml version="1.0"?>
<!-- $Id: clean.xsl,v 1.1 2009/07/29 08:32:50 mike Exp $ -->

<xsl:transform
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:rng="http://relaxng.org/ns/structure/1.0"
	xmlns="http://relaxng.org/ns/structure/1.0"
	version="1.0">
	
  <xsl:key name="refs" match="rng:ref" use="@name"/>

  <xsl:template match="/">
    <xsl:apply-templates mode="clean"/>
  </xsl:template>

  <xsl:template mode="clean" match="rng:text|rng:empty|rng:notAllowed">
    <xsl:if test="not(following-sibling::*[name()=name(current())])">
      <xsl:copy/>
    </xsl:if>
  </xsl:template>

  <xsl:template mode="clean" match="rng:div">
    <xsl:if test=".//*[not(name()='rng:div')]">
      <xsl:copy>
        <xsl:apply-templates mode="clean" select="*|@*|text()|comment()"/>
      </xsl:copy>
    </xsl:if>
  </xsl:template>

  <xsl:template mode="clean" match="rng:define">
    <xsl:if test="key('refs',@name)">
      <xsl:copy>
        <xsl:apply-templates mode="clean" select="*|@*|text()|comment()"/>
      </xsl:copy>
    </xsl:if>
  </xsl:template>

  <xsl:template mode="clean" match="*|@*|text()|comment()">
    <xsl:copy>
      <xsl:apply-templates mode="clean" select="*|@*|text()|comment()"/>
    </xsl:copy>
  </xsl:template>

</xsl:transform>

--- NEW FILE: inc.xsl ---
<?xml version="1.0"?>
<!-- $Id: inc.xsl,v 1.1 2009/07/29 08:32:50 mike Exp $ -->

<xsl:transform
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:rng="http://relaxng.org/ns/structure/1.0"
	xmlns="http://relaxng.org/ns/structure/1.0"
	version="1.0">

  <xsl:template match="/">
    <xsl:apply-templates mode="inc"/>
  </xsl:template>

  <xsl:template mode="inc" match="rng:externalRef">
    <rng:div><xsl:text>
</xsl:text><xsl:comment>externalRef "<xsl:value-of select="@href"/>"</xsl:comment><xsl:text>
</xsl:text>
      <xsl:apply-templates mode="inc" select="*|@*[name()!='href']|text()|comment()"/>
      <xsl:apply-templates mode="inc" select="document(@href,.)"/>
    </rng:div>
  </xsl:template>

  <xsl:template mode="inc" match="rng:include">
    <rng:div><xsl:text>
</xsl:text><xsl:comment>include "<xsl:value-of select="@href"/>"</xsl:comment><xsl:text>
</xsl:text>	
      <xsl:apply-templates mode="inc" select="*|@*[name()!='href']|text()|comment()"/>
      <rng:include>
        <xsl:for-each select="document(@href,.)/rng:grammar">
          <xsl:apply-templates mode="inc" select="*|@*|text()|comment()"/>
	</xsl:for-each>
      </rng:include>
    </rng:div>
  </xsl:template>

  <xsl:template mode="inc" match="*|@*|text()|comment()">
    <xsl:copy>
  	<xsl:apply-templates mode="inc" select="*|@*|text()|comment()"/>
    </xsl:copy>
  </xsl:template>

</xsl:transform>

--- NEW FILE: license.txt ---
Copyright (c) 2003, David Tolpin, Davidashen 
http://davidashen.net/

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.
3. Neither the name of Davidashen nor the names of its
   contributors may be used to endorse or promote products derived
   from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS", AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--- NEW FILE: incelim.xsl ---
<?xml version="1.0"?>
<!-- $Id: incelim.xsl,v 1.1 2009/07/29 08:32:50 mike Exp $ -->

<!-- XSLT glue for incelim; 
  - xsltproc compiled against libxml 20604, libxslt 10102 and libexslt 802
    and earlier versions cannot be used with this stylesheets due to bugs
    in implementation of exsl:node-set();
  
  - SAXON 6.5.[23] and jd.xslt 1.5.5 are slow, a patch for SAXON 6.5.3 that
    makes it fast is included in the distribution (saxon-6.5.3.diff).
  -->


<xsl:transform
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:exsl="http://exslt.org/common"
	extension-element-prefixes="exsl"
	xmlns:rng="http://relaxng.org/ns/structure/1.0"
	xmlns="http://relaxng.org/ns/structure/1.0"
	version="1.0">
	
  <xsl:import href="inc.xsl"/>
  <xsl:import href="elim.xsl"/>
  <xsl:import href="strip.xsl"/>
  <xsl:import href="clean.xsl"/>

  <xsl:param name="rinses">1</xsl:param>
  <xsl:param name="debug">0</xsl:param>

  <xsl:template match="/">
    <xsl:if test="$debug=1">
	<xsl:message>including</xsl:message>
    </xsl:if>
    <xsl:variable name="inc">
	<xsl:apply-templates mode="inc"/>
    </xsl:variable>

    <xsl:if test="$debug=1">
	<xsl:message>splicing</xsl:message>
    </xsl:if>
    <xsl:variable name="elim">
	<xsl:apply-templates select="exsl:node-set($inc)" mode="elim"/>
    </xsl:variable>

    <xsl:call-template name="rinse">
	<xsl:with-param name="rng" select="$elim"/>
	<xsl:with-param name="rinses" select="$rinses"/>
    </xsl:call-template>

  </xsl:template>

  <xsl:template name="rinse">
    <xsl:param name="rng"/>
    <xsl:param name="rinses"/>
	
    <xsl:choose>
      <xsl:when test="$rinses != 0">
	<xsl:variable name="strip">
	  <xsl:if test="$debug=1">
	    <xsl:message>stripping</xsl:message>
	  </xsl:if>
	  <xsl:apply-templates select="exsl:node-set($rng)" mode="strip"/>
	</xsl:variable>
	<xsl:call-template name="rinse">
	  <xsl:with-param name="rng">
	    <xsl:if test="$debug=1">
	      <xsl:message>cleaning</xsl:message>
	    </xsl:if>
	    <xsl:apply-templates select="exsl:node-set($strip)" mode="clean"/>	
	  </xsl:with-param>
	  <xsl:with-param name="rinses" select="$rinses - 1"/>
	</xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
	<xsl:copy-of select="$rng"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:transform>

--- NEW FILE: readme.txt ---

incelim -- Relax NG Splicer

Version 1

   Table of Contents

   Package Contents
   Invocation
   Aknowledgements
   Terms and Conditions
   News and updates

   Abstract

   incelim takes a Relax NG grammar in XML syntax, expands all includes
   and externalRefs, and optionally replaces references to text, empty,
   or notAllowed with the patterns. The result is a 'compiled' schema
   convenient for distribution.

   The package includes stylesheets for each of the transformation steps,
   and two kinds of glue: XSLT stylesheet incelim.xsl, which chains the
   transformations using exsl:node-set(), and a shell script, incelim,
   which applies each of the stylesheets to the serialized result of the
   previous one.

Package Contents

   inc.xsl
          literally inserts contents of included files (and
          externalRefs);

   elim.xsl
          removes overriden defines;

   strip.xsl
          splices references to single parameterless patterns
          (text,empty,notAllowed);

   clean.xsl
          filters out empty divs and unreferenced defines;

   incelim.xsl
          XSLT glue to chain the transformations;

   incelim
          (ash or bash) shell script to run each of the transformations
          in order;

   saxon-6.5.3.diff
          performance patch for SAXON 6.5.3;

   readme.txt, readme.dbx
          brief description in plain text and DocBook XML formats;

   license.txt
          the license.

Invocation

   For the XSLT glue, the arguments are the source schema and the
   stylesheet. Parameter rinses specifies the number of times to apply
   strip/clean phase (it should be recursive, but it would be too complex
   for XSLT to stop timely). 1 is the default, more than 3 does not make
   sense in most practical cases.

Note

     * xsltproc compiled against libxml 20604, libxslt 10102 and libexslt
       802 and earlier versions cannot be used with this stylesheets due
       to bugs in implementation of exsl:node-set();
     * SAXON 6.5. and jd.xslt 1.5.5 are slow, a patch for SAXON 6.5.3
       that makes it fast is included in the distribution
       (saxon-6.5.3.diff).

   The shell script takes a list of schema files and puts the result for
   each schema.rng into schema-compiled.rng. Additionally,the following
   command-line options are accepted:

   -nnn
          number of strip/clean passes (default is -1)

   -processor
          XSLT processor to use, default is -saxon, other options are xt,
          jd.xslt, xalan, 4xslt, xsltproc

   Environment variable INCELIM should point to the directory containing
   XSLT scripts, default is /usr/local/lib/incelim. Temporary files are
   created in a directory pointed to by environment variable TMPDIR, /tmp
   by default.

Aknowledgements

   I would like to thank Sebastian Rahtz for the idea, inspiration,
   sample stylesheet using exsl:node-set(), and testing of the program.

Terms and Conditions

   This software is distributed under BSD license. The details are in
   license.txt.

News and updates

   Visit http://davidashen.net/.

Received on Wednesday, 29 July 2009 08:33:03 UTC