Skip to content

Commit

Permalink
Merge pull request #131 from Edirom/issue-126
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jettka authored Dec 15, 2022
2 parents 8855ce4 + 3bc7654 commit 9ad2ca5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 75 deletions.
2 changes: 1 addition & 1 deletion data/incipit_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
</incip>
<creation xml:id="creation_a9b88e21"/>
<history xml:id="history_5b845292">
<p>As MerMEId does not include a music notation editor, incipits encoded in MEI cannot be entered or edited directly in MerMEId. You can add MEI incipits, however, by uploading MEI files containing the encodings. When uploading an MEI file, MerMEId makes a copy of the first &amp;lt;score&amp;gt; element it encounters (whether in the file's header or in the &amp;lt;music&amp;gt; section) and inserts it as an incipit. If you need to make changes to the incipit, edit your MEI file and upload it again using MerMEId's 'Replace' button.</p>
<p>As MerMEId does not include a music notation editor, incipits encoded in MEI cannot be entered or edited directly in MerMEId. You can add MEI incipits, however, by uploading MEI files containing the encodings. When uploading an MEI file, MerMEId makes a copy of the first 'score' element it encounters (whether in the file's header or in the 'music' section) and inserts it as an incipit. If you need to make changes to the incipit, edit your MEI file and upload it again using MerMEId's 'Replace' button.</p>
</history>
<perfMedium analog="marc:048" auth="marcmusperf" xml:id="perfMedium_5d276875"/>
<classification xml:id="classification_58460514">
Expand Down
92 changes: 18 additions & 74 deletions filter/xsl/filter_put.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@


<xsl:template match="/">
<xsl:variable name="new_doc">
<xsl:apply-templates select="*" mode="convertEntities"/>
</xsl:variable>
<xsl:copy-of select="$new_doc"/>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="m:music" mode="#all">
<xsl:template match="m:music">
<xsl:element name="music" namespace="http://www.music-encoding.org/ns/mei">
<xsl:choose>
<!-- If no new content has been uploaded into <music>, reinstate the original content from the database. -->
Expand All @@ -60,7 +57,7 @@
<!-- CLEANING UP MEI -->

<!-- Generate a value for empty @xml:id -->
<xsl:template match="@xml:id[.='']" mode="#all">
<xsl:template match="@xml:id[.='']">
<xsl:call-template name="fill_in_id"/>
</xsl:template>

Expand All @@ -80,7 +77,7 @@
</xsl:template>

<!-- Change duplicate IDs -->
<xsl:template match="*[@xml:id and count(key('ids', @xml:id)) &gt; 1]" mode="#all">
<xsl:template match="*[@xml:id and count(key('ids', @xml:id)) &gt; 1]">
<xsl:variable name="duplicateID" select="@xml:id"/>
<xsl:element name="{name()}">
<xsl:apply-templates select="@*"/>
Expand All @@ -106,7 +103,7 @@
</xsl:template>

<!-- Add xml:id to certain elements if missing -->
<xsl:template match="m:expression | m:item | m:bibl | m:perfRes | m:perfResList | m:castItem" mode="#all">
<xsl:template match="m:item | m:bibl | m:perfRes | m:perfResList | m:castItem">
<!-- Test if perfResList is like old instrumentation -->
<xsl:element name="{name()}" namespace="http://www.music-encoding.org/ns/mei">
<xsl:apply-templates select="@*"/>
Expand All @@ -117,9 +114,9 @@


<!-- Remove empty attributes -->
<xsl:template match="@accid|@auth|@auth-uri|@cert|@codedval|@count|@enddate|@evidence|
@isodate|@mode|@n|@notafter|@notbefore|@pname|@reg|@resp|
@solo|@startdate|@sym|@target|@targettype|@type|@unit|@xml:lang" mode="#all">
<xsl:template match="@accid|@auth|@auth.uri|@cert|@codedval|@count|@enddate|@evidence|
@isodate|@label|@level|@mode|@n|@notafter|@notbefore|@pname|@reg|@resp|
@solo|@startdate|@sym|@target|@targettype|@type|@unit|@xml:lang">
<xsl:if test="not(normalize-space(data()) = '')">
<xsl:sequence select="."/>
</xsl:if>
Expand All @@ -138,51 +135,6 @@
<xsl:template match="m:titlePage[not(*)]"/>


<!-- Clean up double-escaped ampersands (&amp;) -->
<xsl:template match="text()[contains(.,'&amp;amp;')]">
<xsl:call-template name="cleanup_amp">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:template>

<xsl:template name="cleanup_amp">
<xsl:param name="string"/>
<xsl:variable name="remainder" select="substring-after($string,'&amp;amp;')"/>
<xsl:value-of select="substring-before($string,'&amp;amp;')"/>&amp;<xsl:choose>
<xsl:when test="contains($remainder,'&amp;amp;')">
<xsl:call-template name="cleanup_amp">
<xsl:with-param name="string" select="$remainder"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$remainder"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Trying to convert &nbsp; to &#160; ... -->
<xsl:template match="text()[contains(.,'&amp;nbsp;')]">
<xsl:call-template name="cleanup_nbsp">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:template>

<xsl:template name="cleanup_nbsp">
<xsl:param name="string"/>
<xsl:variable name="remainder" select="substring-after($string,'&amp;nbsp;')"/>
<xsl:value-of select="substring-before($string,'&amp;nbsp;')"/>&#160;<xsl:choose>
<xsl:when test="contains($remainder,'&amp;nbsp;')">
<xsl:call-template name="cleanup_nbsp">
<xsl:with-param name="string" select="$remainder"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$remainder"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<!-- Delete duplicate language definitions (fixes an xforms problem) -->
<xsl:template match="m:mei/m:meiHead/m:workList/m:work/m:langUsage/m:language[. = preceding-sibling::m:language]"/>

Expand All @@ -204,9 +156,9 @@
</xsl:template>


<!-- Ensure correct order of elements -->

<!-- NB: This template only matches in the default mode which is probably never called -->
<!--
Ensure correct order of elements
-->
<xsl:template match="m:biblList">
<xsl:element name="biblList" namespace="http://www.music-encoding.org/ns/mei">
<xsl:apply-templates select="@*"/>
Expand All @@ -216,7 +168,6 @@
</xsl:element>
</xsl:template>

<!-- NB: This template only matches in the default mode which is probably never called -->
<xsl:template match="m:manifestation">
<xsl:element name="manifestation" namespace="http://www.music-encoding.org/ns/mei">
<xsl:apply-templates select="@*"/>
Expand Down Expand Up @@ -245,7 +196,6 @@
</xsl:element>
</xsl:template>

<!-- NB: This template only matches in the default mode which is probably never called -->
<xsl:template match="m:work">
<xsl:element name="work" namespace="http://www.music-encoding.org/ns/mei">
<xsl:apply-templates select="@*"/>
Expand Down Expand Up @@ -278,8 +228,6 @@
</xsl:element>
</xsl:template>


<!-- NB: This template only matches in the default mode which is probably never called -->
<xsl:template match="m:expression">
<xsl:element name="expression" namespace="http://www.music-encoding.org/ns/mei">
<xsl:apply-templates select="@*"/>
Expand Down Expand Up @@ -310,18 +258,14 @@
</xsl:element>
</xsl:template>


<!-- END CLEANING -->


<!-- Convert entities to nodes -->
<xsl:template match="@*|*" mode="convertEntities">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="convertEntities"/>
</xsl:copy>
</xsl:template>

<xsl:template match="text()" mode="convertEntities" priority="1">
<!--
Process all text nodes that feature (escaped) tags
The check for tags looks for end tags (because start tags might bear attributes)
or empty elements.
-->
<xsl:template match="text()[matches(., '(&lt;/\w\s*&gt;)|(&lt;\w\s*/&gt;)')]">
<xsl:call-template name="replace_nodes">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
Expand Down Expand Up @@ -567,7 +511,7 @@
</xsl:template>
<!-- end utilities -->

<xsl:template match="m:revisionDesc" mode="convertEntities">
<xsl:template match="m:revisionDesc">
<xsl:element name="revisionDesc">
<xsl:variable name="penultimate" select="count(m:change)-1"/>
<xsl:variable name="penultimateChange" select="m:change[$penultimate]"/>
Expand Down

0 comments on commit 9ad2ca5

Please sign in to comment.