Skip to content

Commit

Permalink
a few more workarounds for the xsd namespace prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Custer committed Feb 26, 2021
1 parent b92156c commit f63e428
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 208 deletions.
2 changes: 2 additions & 0 deletions build/generate-schemas.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ java -jar %trang% -o disable-abstract-elements -o any-process-contents=lax -o an

java %parameters% %CP% net.sf.saxon.Transform -s:..\xml-schemas\eac-cpf\eac.xsd -xsl:transformations\deglobalize-xsd.xsl -o:..\xml-schemas\eac-cpf\eac.xsd -warnings:silent

java %parameters% %CP% net.sf.saxon.Transform -s:..\xml-schemas\eac-cpf\eac.xsd -xsl:transformations\update-namespace-prefix-in-xsd.xsl -o:..\xml-schemas\eac-cpf\eac.xsd -warnings:silent

rem temporary. will change this later in case we need to process the schematron file before moving.

copy ..\source\modules\schematron\shared-rules.sch ..\xml-schemas\eac-cpf\schematron\eac.sch
Expand Down
2 changes: 2 additions & 0 deletions build/generate-schemas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ java -jar $trang -o disable-abstract-elements -o any-process-contents=lax -o any

java -cp $saxon net.sf.saxon.Transform -s:../xml-schemas/eac-cpf/eac.xsd -xsl:transformations/deglobalize-xsd.xsl -o:../xml-schemas/eac-cpf/eac.xsd

java -cp $saxon net.sf.saxon.Transform -s:../xml-schemas/eac-cpf/eac.xsd -xsl:transformations/update-namespace-prefix-in-xsd.xsl -o:../xml-schemas/eac-cpf/eac.xsd

# temporary. will change this later in case we need to process the schematron file before moving.
cp ../source/modules/schematron/shared-rules.sch ../xml-schemas/eac-cpf/schematron/eac.sch

Expand Down
2 changes: 1 addition & 1 deletion build/transformations/deglobalize-xsd.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<xsl:template match="@type" mode="convert-type-to-extension-element">
<xs:complexContent>
<xs:extension base="{.}" />
<xs:extension base="{.}"/>
</xs:complexContent>
</xsl:template>

Expand Down
34 changes: 34 additions & 0 deletions build/transformations/update-namespace-prefix-in-xsd.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:eac="https://archivists.org/ns/eac/v2"
xmlns:ead3="http://ead3.archivists.org/schema/" xmlns:ead="http://archivists.org/ns/ead/v4"
exclude-result-prefixes="#all" version="3.0">

<xsl:output method="xml" encoding="UTF-8" indent="true"/>
<xsl:mode on-no-match="shallow-copy"/>

<xsl:param name="schema" select="'eac'"/>
<!-- for EAD, will need to pass the param of 'schema', until we change the namespace not to end in 'schema'. this is due to how Trang selects the ns prefix -->

<!-- for eac, this gets us 'https://archivists.org/ns/eac/v2' -->
<xsl:variable name="schema-ns-uri" select="document('')/*/namespace::*[local-name() eq $schema]"/>

<!-- and to get the "v2" prefix from the namespace URI, we do this -->
<xsl:param name="trang-ns-prefix" select="tokenize($schema-ns-uri, '/')[last()]"/>

<xsl:template match="xs:*">
<xsl:element name="{name()}" namespace="{namespace-uri()}">
<xsl:for-each select="namespace::*">
<xsl:namespace name="{if (local-name() = $trang-ns-prefix) then $schema else local-name()}" select="string(.)"/>
</xsl:for-each>
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="@type[starts-with(., $trang-ns-prefix)] | @base[starts-with(., $trang-ns-prefix)]">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="$schema || ':' || substring-after(., ':')"/>
</xsl:attribute>
</xsl:template>

</xsl:stylesheet>
Loading

0 comments on commit f63e428

Please sign in to comment.