Skip to content

Commit

Permalink
Merge branch 'latex-librend' into indices
Browse files Browse the repository at this point in the history
  • Loading branch information
lueck committed Oct 9, 2024
2 parents 6a3d4c7 + 2c42df7 commit 7085b0c
Show file tree
Hide file tree
Showing 8 changed files with 662 additions and 472 deletions.
7 changes: 7 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<antcall target="test-xsl-html-libapp2c.xsl"/>
<antcall target="test-xsl-html-libapp2c-html-librend.xsl"/>
<antcall target="test-xsl-latex-libreledmac.xsl"/>
<antcall target="test-xsl-latex-librend.xsl"/>
<antcall target="test-xsl-latex-libapp2c.xsl"/>
<antcall target="test-xsl-latex-libtext.xsl"/>
<antcall target="test-xsl-latex-libcouplet.xsl"/>
Expand Down Expand Up @@ -96,6 +97,12 @@
</antcall>
</target>

<target name="test-xsl-latex-librend.xsl">
<antcall target="xspec.xspec" inheritall="false">
<param name="xspec.xml" location="${basedir}/xsl/latex/librend.xspec"/>
</antcall>
</target>

<target name="test-xsl-html-prose.xsl">
<antcall target="xspec.xspec" inheritall="false">
<param name="xspec.xml" location="${basedir}/xsl/html/prose.xspec"/>
Expand Down
3 changes: 3 additions & 0 deletions saxon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ http://www.saxonica.com/documentation/index/configuration-file.html
<package
name="https://scdh.zivgitlabpages.uni-muenster.de/tei-processing/transform/xsl/common/librend.xsl"
version="1.0.0" sourceLocation="xsl/common/librend.xsl" priority="10"/>
<package
name="https://scdh.zivgitlabpages.uni-muenster.de/tei-processing/transform/xsl/latex/librend.xsl"
version="1.0.0" sourceLocation="xsl/latex/librend.xsl"/>

<package
name="https://scdh.zivgitlabpages.uni-muenster.de/tei-processing/transform/xsl/common/libref.xsl"
Expand Down
5 changes: 0 additions & 5 deletions xsl/common/libapp2.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,6 @@ see xsl/projects/alea/preview.xsl
apply the rules from 'lemma-text-nodes' on them. -->
<xsl:mode name="app:lemma-text-nodes-dspt" on-no-match="shallow-skip" visibility="public"/>

<!-- The mode apparatus-reading-dspt is for the entries after the lemma (readings, etc.).
It serves as a dispatcher for different types of entries.
All templates should leave it again to get the text of the reading etc. -->
<xsl:mode name="app:reading" on-no-match="shallow-skip" visibility="public"/>


<!-- app -->

Expand Down
183 changes: 183 additions & 0 deletions xsl/latex/librend.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<!-- components for latex output shared in modes text:text, app:reading-text and note:editorial -->
<!DOCTYPE package [
<!ENTITY lb "&#xa;" >
<!ENTITY lre "&#x202a;" >
<!ENTITY rle "&#x202b;" >
<!ENTITY pdf "&#x202c;" >]>
<xsl:package
name="https://scdh.zivgitlabpages.uni-muenster.de/tei-processing/transform/xsl/latex/librend.xsl"
package-version="1.0.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:rend="http://scdh.wwu.de/transform/rend#" xmlns:text="http://scdh.wwu.de/transform/text#"
xmlns:app="http://scdh.wwu.de/transform/app#" xmlns:note="http://scdh.wwu.de/transform/note#"
xmlns:edmac="http://scdh.wwu.de/transform/edmac#" exclude-result-prefixes="#all"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="3.0">

<!-- names of indices (used by imakeidx) -->
<xsl:param name="rend:indices" as="xs:string*" required="false"
select="'person', 'place', 'org', 'event'"/>

<xsl:use-package
name="https://scdh.zivgitlabpages.uni-muenster.de/tei-processing/transform/xsl/latex/libreledmac.xsl"
package-version="1.0.0"/>

<xsl:use-package
name="https://scdh.zivgitlabpages.uni-muenster.de/tei-processing/transform/xsl/common/librend.xsl"
package-version="1.0.0">
<xsl:accept component="mode" names="*" visibility="public"/>

<xsl:override>

<!-- write PIs from latex target to the output -->
<xsl:template mode="text:text app:reading-text note:editorial"
match="processing-instruction('latex')">
<xsl:value-of select="."/>
</xsl:template>

<!-- you may want to override the rule content, e.g., by \txarb{.} -->
<xsl:template mode="text:text app:reading-text note:editorial" match="text()">
<!-- some characters need to be escaped -->
<!--xsl:value-of select=". => replace('\[', '\\lbrack{}') => replace('\]', '\\rbrack{}')"/-->
<!--xsl:value-of select=". => replace('([\[])', '{$1}')"/-->
<xsl:value-of select="."/>
</xsl:template>

<!-- shrink multiple whitespace space characters to a single space -->
<xsl:template mode="text:text app:reading-text note:editorial"
match="text()[ancestor::p or ancestor::l or ancestor::head]">
<xsl:value-of select=". => replace('\s+', ' ')"/>
</xsl:template>

<!-- add hooks everywhere -->
<xsl:template mode="text:text app:reading-text note:editorial" match="*">
<xsl:call-template name="rend:hooks"/>
</xsl:template>


<!-- named entities make up indices. Its up to downstream packages to use them or to let the go. -->

<xsl:template mode="text:text app:reading-text note:editorial" match="rs">
<xsl:call-template name="rend:index-entity">
<xsl:with-param name="index" select="@type"/>
</xsl:call-template>
</xsl:template>

<xsl:template mode="text:text app:reading-text note:editorial" match="persName">
<xsl:call-template name="rend:index-entity">
<xsl:with-param name="index">person</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template mode="text:text app:reading-text note:editorial" match="placeName">
<xsl:call-template name="rend:index-entity">
<xsl:with-param name="index">place</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template mode="text:text app:reading-text note:editorial" match="orgName">
<xsl:call-template name="rend:index-entity">
<xsl:with-param name="index">org</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template mode="text:text app:reading-text note:editorial" match="eventName">
<xsl:call-template name="rend:index-entity">
<xsl:with-param name="index">event</xsl:with-param>
</xsl:call-template>
</xsl:template>

</xsl:override>
</xsl:use-package>

<!-- hooks -->
<xsl:mode name="rend:hook-ahead" on-no-match="deep-skip" visibility="public"/>
<xsl:mode name="rend:hook-before" on-no-match="deep-skip" visibility="public"/>
<xsl:mode name="rend:hook-after" on-no-match="deep-skip" visibility="public"/>
<xsl:mode name="rend:hook-behind" on-no-match="deep-skip" visibility="public"/>

<xsl:template name="rend:hooks" visibility="public">
<xsl:context-item as="element()" use="required"/>
<xsl:apply-templates mode="rend:hook-ahead" select="."/>
<xsl:call-template name="edmac:edlabel">
<xsl:with-param name="suffix" select="'-start'"/>
</xsl:call-template>
<xsl:apply-templates mode="rend:hook-before" select="."/>
<!-- #current mode on children.
This works albeit we are in a named template!
Its guaranteed by the specs. Quote From the XSLT 3.0 TR:
"Definition: At any point in the processing of a stylesheet,
there is a current mode." -->
<xsl:apply-templates mode="#current"/>
<xsl:apply-templates mode="rend:hook-after" select="."/>
<xsl:call-template name="edmac:edlabel">
<xsl:with-param name="suffix" select="'-end'"/>
</xsl:call-template>
<xsl:apply-templates mode="rend:hook-behind" select="."/>
</xsl:template>


<!-- named template that generates entries to the indices.
This also calls the hooks.
The index parameter should be of the values of rs/@type, i.e., 'person', 'place', 'org', 'event', etc. -->
<xsl:template name="rend:index-entity" visibility="public">
<xsl:context-item as="element()" use="required"/>
<xsl:param name="index" as="xs:string" required="true"/>
<!-- early hooks and start label -->
<xsl:apply-templates mode="rend:hook-ahead" select="."/>
<xsl:call-template name="edmac:edlabel">
<xsl:with-param name="suffix" select="'-start'"/>
</xsl:call-template>
<xsl:apply-templates mode="rend:hook-before" select="."/>
<!-- output index macro -->
<xsl:for-each select="rend:index-keys(., $index)">
<xsl:text>\index[</xsl:text>
<xsl:value-of select="$index"/>
<xsl:text>]{</xsl:text>
<xsl:value-of select="."/>
<xsl:text>}</xsl:text>
</xsl:for-each>
<!-- current mode on children -->
<xsl:apply-templates mode="#current"/>
<!-- late hooks and ending label -->
<xsl:apply-templates mode="rend:hook-after" select="."/>
<xsl:call-template name="edmac:edlabel">
<xsl:with-param name="suffix" select="'-end'"/>
</xsl:call-template>
<xsl:apply-templates mode="rend:hook-behind" select="."/>
</xsl:template>

<!-- likely to be replaced with a more sophisticated function that gets names for keys -->
<xsl:function name="rend:index-keys" as="xs:string*" visibility="public">
<xsl:param name="context" as="element()"/>
<xsl:param name="index" as="xs:string"/>
<xsl:variable name="keys" as="xs:string*">
<xsl:choose>
<xsl:when test="$context/@key">
<xsl:value-of select="$context/@key"/>
</xsl:when>
<xsl:when test="$context/@ref">
<xsl:value-of select="$context/@ref => replace('#', '')"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:sequence select="tokenize($keys)"/>
</xsl:function>


<!-- contributions to the latex prologue -->
<xsl:template name="rend:latex-header-index" visibility="public">
<xsl:context-item as="item()" use="required"/>
<xsl:text>&lb;\makeatletter%</xsl:text>
<xsl:text>&lb;\@ifpackageloaded{imakeidx}{}{\usepackage{imakeidx}}%</xsl:text>
<xsl:text>&lb;\makeatother%</xsl:text>
<xsl:for-each select="(root(.)//rs/@type ! string(), $rend:indices) => distinct-values()">
<xsl:text>&lb;\makeindex[name=</xsl:text>
<xsl:value-of select="."/>
<xsl:text>,title={</xsl:text>
<xsl:value-of select="."/>
<xsl:text>}]</xsl:text>
</xsl:for-each>
<xsl:text>&lb;&lb;</xsl:text>
</xsl:template>

</xsl:package>
90 changes: 90 additions & 0 deletions xsl/latex/librend.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ht="http://www.w3.org/1999/xhtml"
xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:app="http://scdh.wwu.de/transform/app#"
xmlns:text="http://scdh.wwu.de/transform/text#" xmlns:t="http://www.tei-c.org/ns/1.0"
xmlns:edmac="http://scdh.wwu.de/transform/edmac#" stylesheet="librend.xsl"
run-as="external">

<x:variable name="x:saxon-config" href="../../saxon.he.xml"/>


<x:scenario label="index from persName">
<x:context mode="text:text">
<tei:persName ref="#oma">Oma</tei:persName>
</x:context>
<x:expect label="has start label" test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}')"/>
<x:expect label="has end label" test="matches(., '\\edlabel\{[a-zA-Z0-9]+-end\}$')"/>
<x:expect label="has index entry" test="matches(., '\\index\[person\]\{oma\}')"/>
<x:expect label="has text" test="matches(., 'Oma')"/>
<x:expect label="result"
test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}\\index\[person\]\{oma\}Oma\\edlabel\{[a-zA-Z0-9]+-end\}$')"
/>
</x:scenario>

<x:scenario label="index from placeName">
<x:context mode="text:text">
<tei:placeName ref="#rome">Roma</tei:placeName>
</x:context>
<x:expect label="has start label" test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}')"/>
<x:expect label="has end label" test="matches(., '\\edlabel\{[a-zA-Z0-9]+-end\}$')"/>
<x:expect label="has index entry" test="matches(., '\\index\[place\]\{rome\}')"/>
<x:expect label="has text" test="matches(., 'Roma')"/>
<x:expect label="result"
test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}\\index\[place\]\{rome\}Roma\\edlabel\{[a-zA-Z0-9]+-end\}$')"
/>
</x:scenario>

<x:scenario label="index from orgName">
<x:context mode="text:text">
<tei:orgName key="teic">TEI-C</tei:orgName>
</x:context>
<x:expect label="has start label" test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}')"/>
<x:expect label="has end label" test="matches(., '\\edlabel\{[a-zA-Z0-9]+-end\}$')"/>
<x:expect label="has index entry" test="matches(., '\\index\[org\]\{teic\}')"/>
<x:expect label="has text" test="matches(., 'TEI-C')"/>
<x:expect label="result"
test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}\\index\[org\]\{teic\}TEI-C\\edlabel\{[a-zA-Z0-9]+-end\}$')"
/>
</x:scenario>

<x:scenario label="index from eventName">
<x:context mode="text:text">
<tei:eventName ref="#pragueDefenestration">Prager Fenstersturz</tei:eventName>
</x:context>
<x:expect label="has start label" test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}')"/>
<x:expect label="has end label" test="matches(., '\\edlabel\{[a-zA-Z0-9]+-end\}$')"/>
<x:expect label="has index entry"
test="matches(., '\\index\[event\]\{pragueDefenestration\}')"/>
<x:expect label="has text" test="matches(., 'Prager\s*Fenstersturz')"/>
<x:expect label="result"
test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}\\index\[event\]\{pragueDefenestration\}Prager Fenstersturz\\edlabel\{[a-zA-Z0-9]+-end\}$')"
/>
</x:scenario>

<x:scenario label="index from rs of type place">
<x:context mode="text:text">
<tei:rs type="place" ref="#rome">Roma</tei:rs>
</x:context>
<x:expect label="has start label" test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}')"/>
<x:expect label="has end label" test="matches(., '\\edlabel\{[a-zA-Z0-9]+-end\}$')"/>
<x:expect label="has index entry" test="matches(., '\\index\[place\]\{rome\}')"/>
<x:expect label="has text" test="matches(., 'Roma')"/>
<x:expect label="result"
test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}\\index\[place\]\{rome\}Roma\\edlabel\{[a-zA-Z0-9]+-end\}$')"
/>
</x:scenario>

<x:scenario label="multiple index entries from rs of type place">
<x:context mode="text:text">
<tei:rs type="place" ref="#cologne #hamburg #munich #berlin" xml:space="preserve">in deutschen Städte mit mehr als einer Million Einwohnern</tei:rs>
</x:context>
<x:expect label="has start label" test="matches(., '^\\edlabel\{[a-zA-Z0-9]+-start\}')"/>
<x:expect label="has end label" test="matches(., '\\edlabel\{[a-zA-Z0-9]+-end\}$')"/>
<x:expect label="has index entries"
test="matches(., '\\index\[place\]\{cologne\}\\index\[place\]\{hamburg\}\\index\[place\]\{munich\}\\index\[place\]\{berlin\}')"
/>
</x:scenario>

</x:description>
Loading

0 comments on commit 7085b0c

Please sign in to comment.