Skip to content

Commit

Permalink
Update copy.xsl
Browse files Browse the repository at this point in the history
* Fix: update schema reference URI to match actual local path
* Fix: add missing attributes on TEI element
* Fix: remove empty `@xml:lang` on xicluded elements
* Fix: remove surplus xml-lang prcessing-instructions from xincluded files
* Fix: remove `@xml:base` on xincluded files as those would render all relative targets unavailable
  • Loading branch information
bwbohl committed Oct 17, 2021
1 parent 7482a4b commit 3697ec0
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions utils/canonicalization/copy.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="xs math xd"
exclude-result-prefixes="xsl xs math xd xi"
version="3.0">
<xd:doc scope="stylesheet">
<xd:desc>
Expand All @@ -17,33 +18,55 @@

<xsl:output indent="false"></xsl:output>

<xsl:template match="node()|@*">
<xsl:template match="node()|@*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>

<xsl:template match="processing-instruction('xml-model')">
<xsl:text>&#xa;</xsl:text>
<xsl:template match="processing-instruction('xml-model')" mode="clone">
<xsl:copy/>
</xsl:template>

<xsl:template match="processing-instruction('xml-model')" mode="cleanup"/>

<xsl:template match="/processing-instruction('xml-model')" mode="cleanup">
<xsl:variable name="pi-value.tokens" select="tokenize(., ' ')"/>
<xsl:variable name="pi-href" select="replace($pi-value.tokens[1], '&quot;validation/', '../../../source/&quot;validation/' )"/>
<xsl:text>&#xa;</xsl:text>
<xsl:processing-instruction name="xml-model">
<xsl:value-of select="$pi-href, $pi-value.tokens[position() > 1]" separator=" "/>
</xsl:processing-instruction>
</xsl:template>

<xsl:template match="/">
<xsl:variable name="xincluded">
<xsl:apply-templates/>
</xsl:variable>
<xsl:apply-templates select="$xincluded" mode="cleanup"/>
</xsl:template>

<xsl:template match="/" mode="cleanup">
<xsl:text>&#xa;</xsl:text>
<xsl:copy>
<xsl:apply-templates select="node()"/>
<xsl:apply-templates select="node()" mode="cleanup"/>
</xsl:copy>
</xsl:template>

<xsl:template match="tei:TEI">
<xsl:template match="tei:TEI" mode="cleanup">
<xsl:text>&#xa;</xsl:text>
<xsl:comment>
<xsl:text>canonicalized: </xsl:text>
<xsl:value-of select="current-dateTime()"/>
</xsl:comment>
<xsl:text>&#xa;</xsl:text>
<xsl:copy>
<xsl:apply-templates select="node()"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()" mode="cleanup"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

<xsl:template match="@xml:lang[. = '']" mode="cleanup"/>

<xsl:template match="@xml:base" mode="cleanup"/>
</xsl:stylesheet>

0 comments on commit 3697ec0

Please sign in to comment.