Skip to content

Commit

Permalink
Run generate_static_articles.xsl using the Ant buildfile.
Browse files Browse the repository at this point in the history
The XSLT now passes parameters onto template_article.xsl, and
generates a mapping between source and static article directories.

Fix bug in head.xsl: when multiple <title>s are provided, only the
first is used.
  • Loading branch information
amclark42 committed Apr 4, 2023
1 parent 4bcf21a commit 645fda0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
14 changes: 13 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@
<!-- Generate static HTML versions of the DHQ articles. -->
<target name="generateArticles">
<mkdir dir="${toDir}/${context}/vol"/>

<!-- Transform the article with XSLT. -->
<xslt in="toc/toc.xml"
out="${toDir}/article-map.xml"
style="common/xslt/generate_static_articles.xsl"
classpath="${processor.location}"
force="true"
failonerror="false">
<factory name="${processor.name}"/>
<param name="context" expression="${context}"/>
<param name="dir-separator" expression="${file.separator}"/>
<!--<param name="repo-dir" expression="${basedir}"/>-->
<param name="static-dir" expression="${toDir}/${context}"/>
</xslt>
</target>

<!-- Generate a static version of the DHQ website. -->
Expand Down
42 changes: 35 additions & 7 deletions common/xslt/generate_static_articles.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
xmlns:dhq="http://www.digitalhumanities.org/ns/dhq"
xmlns:err="http://www.w3.org/2005/xqt-errors"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
Expand All @@ -21,7 +22,8 @@
2023
-->

<xsl:output encoding="UTF-8" method="xhtml" omit-xml-declaration="no"/>
<xsl:output encoding="UTF-8" indent="yes" method="xhtml"
omit-xml-declaration="no"/>

<!-- PARAMETERS -->

Expand All @@ -36,6 +38,8 @@

<xsl:param name="static-dir" as="xs:string" required="yes"/>

<xsl:param name="context" as="xs:string"/>


<!-- GLOBAL VARIABLES -->

Expand All @@ -60,7 +64,9 @@
<!-- TEMPLATES, #default mode -->

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

<xsl:template match="journal[@vol][@issue]">
Expand All @@ -81,21 +87,31 @@
select="string-join(($repo-dir,'articles',$articleId),$dir-separator)"/>
<xsl:variable name="srcPath"
select="concat($srcDir,$dir-separator,$articleId,'.xml')"/>
<xsl:variable name="outArticleDir"
select="concat($outDir,$dir-separator,$articleId)"/>
<!-- Make sure that the TEI article exists before proceeding to transform it. -->
<xsl:choose>
<xsl:when test="doc-available($srcPath)">
<xsl:call-template name="transform-article">
<xsl:with-param name="articleId" select="$articleId"/>
<xsl:with-param name="srcDir" select="$srcDir"/>
<xsl:with-param name="srcPath" select="$srcPath"/>
<xsl:with-param name="outDir"
select="concat($outDir,$dir-separator,$articleId)"/>
<xsl:with-param name="outDir" select="$outArticleDir"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:message select="concat('Could not find an article at ',$srcPath)"/>
</xsl:otherwise>
</xsl:choose>
<!-- Finally, map the source directory and the output directory, for later use. -->
<dir>
<src>
<xsl:value-of select="replace($srcDir, '^file:', '')"/>
</src>
<out>
<xsl:value-of select="replace($outArticleDir, '^file:', '')"/>
</out>
</dir>
</xsl:template>


Expand All @@ -121,7 +137,15 @@
map:entry('stylesheet-location', $altXslPath)
else $xsl-map-base"/>
<xsl:variable name="otherEntries"
select="map:entry('source-node', doc($srcPath))"/>
select="map {
'source-node': doc($srcPath),
'stylesheet-params': map {
QName((),'context'): $context,
QName((),'vol'): $vol,
QName((),'issue'): $issue,
QName((),'fpath'): concat($outDir,'/',$articleId,'.html')
}
}"/>
<xsl:sequence select="map:merge(($useStylesheet, $otherEntries))"/>
</xsl:variable>
<!-- Copy the TEI source to the output directory. -->
Expand All @@ -135,8 +159,12 @@
<xsl:sequence select="transform($xslMap)?output"/>
</xsl:result-document>
<xsl:catch>
<xsl:message>Something went wrong in transforming article
<xsl:value-of select="$articleId"/>.</xsl:message>
<xsl:message>
<xsl:text>Something went wrong in transforming article </xsl:text>
<xsl:value-of select="$articleId"/>
</xsl:message>
<xsl:message select="$err:module"/>
<xsl:message select="$err:description"/>
</xsl:catch>
</xsl:try>
</xsl:template>
Expand Down
7 changes: 6 additions & 1 deletion common/xslt/head.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
<xsl:value-of select="concat('DHQ: Digital Humanities Quarterly: ',$title)"/>
<!-- Articles can have more than one <title> in <titleStmt> if more
than one language is represented. By default, this stylesheet will
take the first one offered. To ensure that the expected title is
used, check for multiple <title>s and choose one before calling
the "head" template. -->
<xsl:value-of select="concat('DHQ: Digital Humanities Quarterly: ',$title[1])"/>
</title>
<link rel="stylesheet" type="text/css" href="{$assets-path}common/css/dhq.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="{$assets-path}common/css/dhq_screen.css"/>
Expand Down
2 changes: 1 addition & 1 deletion common/xslt/template_article.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<xsl:param name="id">
<xsl:value-of select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:idno[@type='DHQarticle-id']"/>
</xsl:param>-->
<xsl:param name="fpath" select="concat('vol/',$vol,'/',$issue,'/',$id,'.html')"/>
<xsl:param name="fpath" select="concat('vol/',$vol,'/',$issue,'/',$id,'/',$id,'.html')"/>
<xsl:param name="error"/>
<xsl:param name="staticPublishingPath">
<xsl:value-of select="'../../articles/'"/>
Expand Down

0 comments on commit 645fda0

Please sign in to comment.