Skip to content

Commit

Permalink
src, metadata-ms-verses, cf. #8
Browse files Browse the repository at this point in the history
  • Loading branch information
pdaengeli committed Oct 4, 2024
1 parent d9931f2 commit 4dede2f
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/generate.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<xsl:include href="util/flatten-originals.xsl"/>
<xsl:include href="util/contiguous-ranges.xsl"/>
<xsl:include href="util/metadata-ms-page.xsl"/>
<xsl:include href="util/metadata-ms-verses.xsl"/>
<xsl:include href="util/extract-fragment-metadata.xsl"/>

<xd:doc>
Expand Down Expand Up @@ -80,6 +81,14 @@
<xsl:with-param name="task" as="xs:string" select="'metadata-ms-page'"/>
</xsl:call-template>

<xsl:call-template name="metadata-ms-verses" use-when="$all or $do => contains-token('metadata-ms-verses')">
<xsl:with-param name="repository" as="xs:string" select="$repository"/>
<xsl:with-param name="path_src" as="xs:string" select="$path_src"/>
<xsl:with-param name="path_api" as="xs:string" select="$path_api"/>
<xsl:with-param name="verbose" as="xs:boolean" select="$verbose"/>
<xsl:with-param name="task" as="xs:string" select="'metadata-ms-verses'"/>
</xsl:call-template>

<xsl:if test="$do='' and not($all)">
<xsl:message>No action defined. Use parameter $do (tasks as tokens) or $all (boolean).</xsl:message>
</xsl:if>
Expand Down
8 changes: 4 additions & 4 deletions src/util/metadata-ms-page.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

<!-- local params -->
<xd:doc>
<xd:param name="split-output">Generate multiple (true) or one output file (false).</xd:param>
<xd:param name="split-output-pages">Generate multiple (true) or one output file (false).</xd:param>
</xd:doc>
<xsl:param name="split-output" static="true" select="true()"/>
<xsl:param name="split-output-pages" static="true" select="true()"/>

<xd:doc scope="template">
<xd:desc>
Expand Down Expand Up @@ -108,14 +108,14 @@
<xsl:message use-when="$verbose">Starting task: {$task}</xsl:message>

<!-- outputting one file per document -->
<xsl:for-each select="$payload/*:map" use-when="$split-output">
<xsl:for-each select="$payload/*:map" use-when="$split-output-pages">
<xsl:message use-when="$verbose">…writing {$path_api}/json/metadata-ms-page/{*:array/@key}.json…</xsl:message>
<xsl:result-document href="{$path_api}/json/metadata-ms-page/{*:array/@key}.json" method="json" indent="true">
<xsl:sequence select=". => xml-to-json(map { 'indent' : true() }) => parse-json()"/>
</xsl:result-document>
</xsl:for-each>

<xsl:result-document href="{$path_api}/json/metadata-ms-page.json" method="json" indent="false" use-when="not($split-output)">
<xsl:result-document href="{$path_api}/json/metadata-ms-page.json" method="json" indent="false" use-when="not($split-output-pages)">
<xsl:variable name="payload">
<map>
<array key="pages">
Expand Down
101 changes: 101 additions & 0 deletions src/util/metadata-ms-verses.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns="http://www.w3.org/2005/xpath-functions"
xmlns:dsl="https://dsl.unibe.ch"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
expand-text="true"
exclude-result-prefixes="dsl xs xd map array"
version="3.0">
<xd:doc scope="stylesheet">
<xd:desc>
<xd:p><xd:b>Created on:</xd:b> Oct 4, 2024</xd:p>
<xd:p><xd:b>Author:</xd:b> pd</xd:p>
<xd:p></xd:p>
</xd:desc>
</xd:doc>

<!-- local params -->
<xd:doc>
<xd:param name="split-output-verses">Generate multiple (true) or one output file (false).</xd:param>
</xd:doc>
<xsl:param name="split-output-verses" static="true" select="true()"/>

<xd:doc scope="template">
<xd:desc>
<xd:p><xd:b>metadata-ms-verses</xd:b></xd:p>
<xd:p>Generate information on all verses per manuscript.</xd:p>
</xd:desc>
<xd:param name="repository">Repository name.</xd:param>
<xd:param name="path_src">Relative path to source directory.</xd:param>
<xd:param name="path_api">Relative path to target directory.</xd:param>
<xd:param name="verbose">Toggle verbose output (true/false).</xd:param>
<xd:param name="task">Task name.</xd:param>
</xd:doc>
<xsl:template name="metadata-ms-verses">
<xsl:param name="repository" select="()"/>
<xsl:param name="path_src" as="xs:string"/>
<xsl:param name="path_api" as="xs:string"/>
<xsl:param name="task" as="xs:string"/>
<xsl:param name="verbose" as="xs:boolean"/>
<xsl:variable name="documents" as="element(Q{https://dsl.unibe.ch}documents)">
<documents xmlns="https://dsl.unibe.ch">
<xsl:for-each select="uri-collection($path_src||'data/original/transcription?recurse=yes;select=*.xml')"><!-- [position() lt 5] -->
<xsl:variable name="document" as="xs:string" select="doc(.) => base-uri() => replace('.+/(.+)\.xml','$1')"/>
<doc n="{$document}">
<xsl:for-each select="doc(.)//body//l">
<l n="{@xml:id}"/>
</xsl:for-each>
</doc>
<xsl:sequence select="$document"/>
</xsl:for-each>
</documents>
</xsl:variable>

<xsl:variable name="payload">
<xsl:for-each select="$documents/dsl:doc">
<map>
<map key="meta">
<string key="task">{$task}</string>
<string key="generated-by">{let $regex := '.*('||$repository||'/.+)' return base-uri() => replace($regex,'$1')}</string>
<string key="generated-on">{current-dateTime()}</string>
<string key="description">Verse numbers contained in source document.</string>
</map>
<array key="{@n}">
<xsl:for-each select="dsl:l">
<string>{@n/data()}</string>
</xsl:for-each>
</array>
</map>
</xsl:for-each>
</xsl:variable>

<xsl:message use-when="$verbose">Starting task: {$task}</xsl:message>

<!-- outputting one file per document -->
<xsl:for-each select="$payload/*:map" use-when="$split-output-verses">
<xsl:message use-when="$verbose">…writing {$path_api}/json/metadata-ms-verses/{*:array/@key}.json…</xsl:message>
<xsl:result-document href="{$path_api}/json/metadata-ms-verses/{*:array/@key}.json" method="json" indent="true">
<xsl:sequence select=". => xml-to-json(map { 'indent' : true() }) => parse-json()"/>
</xsl:result-document>
</xsl:for-each>

<xsl:result-document href="{$path_api}/json/metadata-ms-verses.json" method="json" indent="false" use-when="not($split-output-verses)">
<xsl:variable name="payload">
<map>
<array key="pages">
<xsl:sequence select="$payload"/>
</array>
</map>
</xsl:variable>
<xsl:message use-when="$verbose">…writing {$path_api}/json/metadata-ms-verses.json…</xsl:message>
<xsl:sequence select="$payload => xml-to-json(map { 'indent' : true() }) => parse-json()"/>
</xsl:result-document>

<xsl:message>Task `{$task}` done.</xsl:message>
</xsl:template>

</xsl:transform>

0 comments on commit 4dede2f

Please sign in to comment.