Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Nov 6, 2019
2 parents c02135d + 143187d commit dbc6cfc
Show file tree
Hide file tree
Showing 11 changed files with 1,858 additions and 1,490 deletions.
56 changes: 46 additions & 10 deletions tei2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,27 @@ def check_executables():

def main(
input_file,
root_dir
root_dir,
xslt_file,
params,
output_file = None
):
"""Main function"""

exec_command(
"saxon -t -s:{input_file} -xsl:{xslt_file} domain={root_dir}".format(
xslt_file = (BASE_DIR / SCRIPT_NAME) . with_suffix( ".xsl" ),
output_options = ""
if output_file is not None:
output_options = f"-o:{output_file}"
cmd = \
"saxon -t {output_options} -s:{input_file} -xsl:{xslt_file} domain={root_dir}".format(
xslt_file = (BASE_DIR / "tei2html" / xslt_file),
input_file = input_file,
root_dir = root_dir
),
root_dir = root_dir,
output_options = output_options
)
for param in params:
cmd += (" " + param)
exec_command(
cmd
)

# def main ends here
Expand All @@ -51,7 +62,7 @@ def main(
)
parser.add_argument(
"-l", "--log-file",
default = Path("logs", SCRIPT_NAME).with_suffix(".log"),
# default = Path("logs", SCRIPT_NAME).with_suffix(".log"),
help="logfile"
)
parser.add_argument(
Expand All @@ -64,11 +75,28 @@ def main(
default = Path.cwd(),
help="internal html links on the page will use this location as a prefix"
)
parser.add_argument(
"-p", "--param",
action = 'append',
default = [],
help="internal html links on the page will use this location as a prefix"
)
parser.add_argument(
"-x", "--xsl",
default = "tei2html.xsl",
help="name of the xsl file in '{dir}/'".format(
dir = BASE_DIR / "tei2html"
)
)
parser.add_argument(
"-f", "--filename",
required = True,
help="Name of main EOA-TEI file"
)
parser.add_argument(
"-o", "--output-file",
help="make saxon redirect the templates output here"
)

'''
TODO: support output directory
Expand All @@ -84,20 +112,28 @@ def main(
CONFIG_FILE = args.config

print("The configfile is '%s'." % CONFIG_FILE)
print("The logfile is '%s'." % args.log_file)
log_file = args.log_file
if log_file is None:
log_file = (Path("logs") / args.xsl).with_suffix(".log")
print("The logfile is '%s'." % log_file)

CONFIG = load_config(
CONFIG_FILE,
args.log_level,
args.log_file,
log_file,
)

check_executables()

print( "params: " + str(args.param) )

# run main:
main(
input_file = args.filename,
root_dir = args.root_dir
root_dir = args.root_dir,
xslt_file = args.xsl,
output_file = args.output_file,
params = args.param,
)

# finis
1,025 changes: 0 additions & 1,025 deletions tei2html.xsl

This file was deleted.

72 changes: 72 additions & 0 deletions tei2html/tei2html.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:eoa="http://www.edition-open-access.de/ns"
exclude-result-prefixes="xs tei eoa"
version="2.0"
>
<xsl:output
method="html"
encoding="UTF-8"
indent="yes"
/>

<xsl:include href="tei2html_index_utils.xsl"/>
<xsl:include href="tei2html_chapter_utils.xsl"/>
<xsl:include href="utils/html_rules.xsl"/>
<xsl:include href="utils/common.xsl"/>

<xsl:param name="output_dir" as="xs:string" select="'.'"/>
<xsl:param name="static_dir" as="xs:string" select="'static'"/>
<xsl:param name="logo_dir" as="xs:string" select="concat($static_dir, '/assets/images')"/>
<xsl:param name="nav_items" as="element(eoa:entry)*">
<eoa:entry active="1">
<eoa:link>
<xsl:text>#</xsl:text>
</eoa:link>
<eoa:title>Publications</eoa:title>
</eoa:entry>
</xsl:param>

<!--
<xsl:param name="verbosity" as="xs:integer" required="no" select="0"/>
-->

<xsl:template match="/">
<xsl:message> domain: <xsl:value-of select="$domain"/> </xsl:message>
<xsl:variable name="output_subdir" as="xs:string">
<xsl:value-of select="concat($output_dir, '/', $series, '/', $publication_number)"/>
</xsl:variable>
<xsl:result-document
method="html"
encoding="UTF-8"
include-content-type="yes"
indent="yes"
href="{concat($output_subdir, '/index.html')}"
>
<xsl:call-template name="writeindexfile">
<xsl:with-param name="static_dir" select="concat('../../', $static_dir)"/>
<xsl:with-param name="logo_dir" select="concat('../../', $logo_dir)"/>
<xsl:with-param name="nav_items" as="element(eoa:entry)*" select="$nav_items"/>
</xsl:call-template>
</xsl:result-document>
<xsl:for-each select="//tei:div[@type='chapter']">
<xsl:result-document
method="html"
encoding="UTF-8"
include-content-type="yes"
indent="yes"
href="{concat($output_subdir, '/', position(), '/index.html')}"
>
<xsl:call-template name="writechapterfile">
<xsl:with-param name="static_dir" select="concat('../../../', $static_dir)"/>
<xsl:with-param name="logo_dir" select="concat('../../../', $logo_dir)"/>
<xsl:with-param name="nav_items" as="element(eoa:entry)*" select="$nav_items"/>
</xsl:call-template>
</xsl:result-document>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
42 changes: 42 additions & 0 deletions tei2html/tei2html_chapter.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:eoa="http://www.edition-open-access.de/ns"
exclude-result-prefixes="xs tei eoa"
version="2.0">

<xsl:param name="static_dir" as="xs:string" select="'static'"/>
<xsl:param name="logo_dir" as="xs:string" select="concat($static_dir, '/assets/images')"/>
<xsl:param name="nav_items" as="element(eoa:entry)*">
<eoa:entry active="1">
<eoa:link>
<xsl:text>#</xsl:text>
</eoa:link>
<eoa:title>Publications</eoa:title>
</eoa:entry>
</xsl:param>
<xsl:param name="chapter_nr" as="xs:integer" required="1"/>

<xsl:output method="html" encoding="UTF-8"/>

<xsl:include href="utils/common.xsl"/>
<xsl:include href="utils/html_rules.xsl"/>
<xsl:include href="tei2html_chapter_utils.xsl"/>

<xsl:template match="/">
<!--
<xsl:message> domain: <xsl:value-of select="$domain"/> </xsl:message>
-->
<xsl:for-each select="(//tei:div[@type='chapter'])[position() = $chapter_nr]">
<xsl:message>printing chapter <xsl:value-of select="$chapter_nr"/>. head: <xsl:value-of select="tei:head"/></xsl:message>
<xsl:call-template name="writechapterfile">
<xsl:with-param name="static_dir" select="$static_dir"/>
<xsl:with-param name="logo_dir" select="$logo_dir"/>
<xsl:with-param name="nav_items" as="element(eoa:entry)*" select="$nav_items"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
Loading

0 comments on commit dbc6cfc

Please sign in to comment.