-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'latex-librend' into indices
- Loading branch information
Showing
8 changed files
with
662 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "
" > | ||
<!ENTITY lre "‪" > | ||
<!ENTITY rle "‫" > | ||
<!ENTITY pdf "‬" >]> | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.