Skip to content

Commit

Permalink
Move some experimental files out of the way.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellingman committed Jul 2, 2016
1 parent e314377 commit 2a4d339
Show file tree
Hide file tree
Showing 10 changed files with 1,534 additions and 1,529 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -58,3 +58,6 @@ images/stock_book_yellow-16.png
images/stock_book-16.png
images/stock_volume-16.png
images/thumbs/cover500.jpg
attic/
test-kwic.html
metadata.xml
4 changes: 2 additions & 2 deletions inclusions.xsl
Expand Up @@ -9,8 +9,8 @@
>

<xd:doc type="stylesheet">
<xd:short>Stylesheet to align paragraphs in two TEI documents.</xd:short>
<xd:detail><p>Stylesheet to align paragraphs in two TEI documents.</p>
<xd:short>Stylesheet to include external files into TEI documents.</xd:short>
<xd:detail><p>Stylesheet to include external files into TEI documents.</p>
</xd:detail>
</xd:doc>

Expand Down
2 changes: 2 additions & 0 deletions sandbox/README.md
@@ -0,0 +1,2 @@

This directory contains unfinished or experimental stylesheets.
22 changes: 11 additions & 11 deletions breaklines.pl → sandbox/breaklines.pl
@@ -1,11 +1,11 @@
# Perl script to test the the tei2wl.xsl stylesheet with Saxon.

use strict;

my $xsldir = "C:\\Users\\Jeroen\\Documents\\eLibrary\\Tools\\tei2html"; # location of xsl stylesheets
my $saxon = "\"C:\\Program Files\\Java\\jre6\\bin\\java.exe\" -jar C:\\bin\\saxonhe9\\saxon9he.jar ";

my $filename = $ARGV[0];

system ("$saxon $filename $xsldir/breaklines.xsl");

# Perl script to test the the tei2wl.xsl stylesheet with Saxon.

use strict;

my $xsldir = "C:\\Users\\Jeroen\\Documents\\eLibrary\\Tools\\tei2html"; # location of xsl stylesheets
my $saxon = "\"C:\\Program Files\\Java\\jre6\\bin\\java.exe\" -jar C:\\bin\\saxonhe9\\saxon9he.jar ";

my $filename = $ARGV[0];

system ("$saxon $filename $xsldir/breaklines.xsl");

288 changes: 144 additions & 144 deletions breaklines.xsl → sandbox/breaklines.xsl
@@ -1,144 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- An experimental XSLT stylesheet to break a paragraph into lines. -->

<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">
<xsl:call-template name="breaklines">
<xsl:with-param name="text" select="'Dit is een kleine test van de functie break-lines. Hiermee moeten we regels in stukjes kunnen breken, zodat de zinnen netjes in een smalle kolom passen.'"/>
</xsl:call-template>
</xsl:template>


<xsl:template name="breaklines">
<xsl:param name="text"/>

<xsl:variable name="tokens">
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="lines">
<xsl:call-template name="lines">
<xsl:with-param name="tokens" select="$tokens"/>
</xsl:call-template>
</xsl:variable>

<paragraph>
<xsl:copy-of select="$lines"/>
</paragraph>
</xsl:template>

<!--
Use analyze-string to split the string into lexical items.
1. box: ([^\s-]+-?)
2. space: (\s+)
-->
<xsl:template name="tokenize">
<xsl:param name="text"/>

<xsl:variable name="patterns" select="'([^-\s]+-?)','(\s+)'"/>

<xsl:analyze-string select="$text" regex="{string-join($patterns, '|')}" flags="s">
<xsl:matching-substring>
<xsl:choose>
<!-- box -->
<xsl:when test="regex-group(1)">
<box>
<xsl:value-of select="regex-group(1)"/>
</box>
</xsl:when>
<!-- glue -->
<xsl:when test="regex-group(2)">
<glue>
<xsl:value-of select="regex-group(2)"/>
</glue>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes" select="'internal error'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:if test="normalize-space()!=''">
<xsl:message select="concat('unknown token: ', .)"/>
</xsl:if>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>


<xsl:template name="lines">
<xsl:param name="tokens"/>

<xsl:variable name="breaks">
<xsl:call-template name="append-next">
<xsl:with-param name="tokens" select="$tokens/*"/>
<xsl:with-param name="max" select="44"/>
<xsl:with-param name="length" select="0"/>
</xsl:call-template>
</xsl:variable>

<xsl:for-each-group select="$breaks/*" group-starting-with="break">
<line length="{string-length(string-join(current-group(), ''))}">
<xsl:apply-templates select="current-group()"/>
</line>
</xsl:for-each-group>


</xsl:template>

<xsl:template name="append-next">
<xsl:param name="tokens"/>
<xsl:param name="max"/>
<xsl:param name="length"/>

<!-- <d length="{$length}"/> -->
<xsl:if test="$tokens">
<xsl:variable name="head" select="$tokens[1]"/>
<xsl:variable name="next" select="$tokens[2]"/>
<xsl:variable name="tail" select="$tokens[position() != 1]"/>
<xsl:choose>

<!-- head is glue and next item does not fit anymore -->
<xsl:when test="$head/self::glue and $length + string-length($head) + string-length($next) &gt; $max ">
<break/>
<xsl:call-template name="append-next">
<xsl:with-param name="tokens" select="$tail"/>
<xsl:with-param name="max" select="$max"/>
<xsl:with-param name="length" select="0"/>
</xsl:call-template>
</xsl:when>

<!-- head is not glue and next not fit anymore -->
<xsl:when test="$length + string-length($head) + string-length($next) &gt; $max">
<xsl:copy-of select="$head"/>
<break/>
<xsl:call-template name="append-next">
<xsl:with-param name="tokens" select="if ($next/self::glue) then $tokens[position() &gt; 2] else $tail"/>
<xsl:with-param name="max" select="$max"/>
<xsl:with-param name="length" select="0"/>
</xsl:call-template>
</xsl:when>

<!-- next does fit -->
<xsl:otherwise>
<xsl:copy-of select="$head"/>
<xsl:call-template name="append-next">
<xsl:with-param name="tokens" select="$tail"/>
<xsl:with-param name="max" select="$max"/>
<xsl:with-param name="length" select="$length + string-length($head)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>

<!-- An experimental XSLT stylesheet to break a paragraph into lines. -->

<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">
<xsl:call-template name="breaklines">
<xsl:with-param name="text" select="'Dit is een kleine test van de functie break-lines. Hiermee moeten we regels in stukjes kunnen breken, zodat de zinnen netjes in een smalle kolom passen.'"/>
</xsl:call-template>
</xsl:template>


<xsl:template name="breaklines">
<xsl:param name="text"/>

<xsl:variable name="tokens">
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="lines">
<xsl:call-template name="lines">
<xsl:with-param name="tokens" select="$tokens"/>
</xsl:call-template>
</xsl:variable>

<paragraph>
<xsl:copy-of select="$lines"/>
</paragraph>
</xsl:template>

<!--
Use analyze-string to split the string into lexical items.
1. box: ([^\s-]+-?)
2. space: (\s+)
-->
<xsl:template name="tokenize">
<xsl:param name="text"/>

<xsl:variable name="patterns" select="'([^-\s]+-?)','(\s+)'"/>

<xsl:analyze-string select="$text" regex="{string-join($patterns, '|')}" flags="s">
<xsl:matching-substring>
<xsl:choose>
<!-- box -->
<xsl:when test="regex-group(1)">
<box>
<xsl:value-of select="regex-group(1)"/>
</box>
</xsl:when>
<!-- glue -->
<xsl:when test="regex-group(2)">
<glue>
<xsl:value-of select="regex-group(2)"/>
</glue>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes" select="'internal error'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:if test="normalize-space()!=''">
<xsl:message select="concat('unknown token: ', .)"/>
</xsl:if>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>


<xsl:template name="lines">
<xsl:param name="tokens"/>

<xsl:variable name="breaks">
<xsl:call-template name="append-next">
<xsl:with-param name="tokens" select="$tokens/*"/>
<xsl:with-param name="max" select="44"/>
<xsl:with-param name="length" select="0"/>
</xsl:call-template>
</xsl:variable>

<xsl:for-each-group select="$breaks/*" group-starting-with="break">
<line length="{string-length(string-join(current-group(), ''))}">
<xsl:apply-templates select="current-group()"/>
</line>
</xsl:for-each-group>


</xsl:template>

<xsl:template name="append-next">
<xsl:param name="tokens"/>
<xsl:param name="max"/>
<xsl:param name="length"/>

<!-- <d length="{$length}"/> -->
<xsl:if test="$tokens">
<xsl:variable name="head" select="$tokens[1]"/>
<xsl:variable name="next" select="$tokens[2]"/>
<xsl:variable name="tail" select="$tokens[position() != 1]"/>
<xsl:choose>

<!-- head is glue and next item does not fit anymore -->
<xsl:when test="$head/self::glue and $length + string-length($head) + string-length($next) &gt; $max ">
<break/>
<xsl:call-template name="append-next">
<xsl:with-param name="tokens" select="$tail"/>
<xsl:with-param name="max" select="$max"/>
<xsl:with-param name="length" select="0"/>
</xsl:call-template>
</xsl:when>

<!-- head is not glue and next not fit anymore -->
<xsl:when test="$length + string-length($head) + string-length($next) &gt; $max">
<xsl:copy-of select="$head"/>
<break/>
<xsl:call-template name="append-next">
<xsl:with-param name="tokens" select="if ($next/self::glue) then $tokens[position() &gt; 2] else $tail"/>
<xsl:with-param name="max" select="$max"/>
<xsl:with-param name="length" select="0"/>
</xsl:call-template>
</xsl:when>

<!-- next does fit -->
<xsl:otherwise>
<xsl:copy-of select="$head"/>
<xsl:call-template name="append-next">
<xsl:with-param name="tokens" select="$tail"/>
<xsl:with-param name="max" select="$max"/>
<xsl:with-param name="length" select="$length + string-length($head)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 2a4d339

Please sign in to comment.