Skip to content

Commit

Permalink
RP XSL - add template to fix source elements
Browse files Browse the repository at this point in the history
- Change to title case when source is in all caps
- If source starts with 'In ', then move this outside of source
  • Loading branch information
fred-atherden committed Nov 25, 2024
1 parent 8232e35 commit d1cd162
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
73 changes: 72 additions & 1 deletion src/preprint-changes.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,40 @@
<xsl:param name="string" as="xs:string"/>
<xsl:value-of select="replace(replace(replace(translate(normalize-unicode($string,'NFD'),'ƀȼđɇǥħɨıɉꝁłøɍŧɏƶ','bcdeghiijklortyz'),'[\p{M}’]',''),'æ','ae'),'ß','ss')"/>
</xsl:function>

<xsl:function name="e:toTitleCase" as="xs:string">
<xsl:param name="input" as="xs:string"/>
<xsl:variable name="upper-exceptions" select="('PLOS','OSF','JOSS','JAMA','EMBO','RNA','BMJ','PRIDE','CRAN','EMDB','SSRN','EMPIAR','NEJM','FEMS','JMLR','APMIS','ISME','FASEB','PNAS','JBO','JBJS','AAPS','NIPS','BJOG','ISMRM')"/>
<xsl:variable name="case-exceptions" select="('eLife','iScience','eNeuro','arXiv','bioRxiv','medRxiv','ChemRxiv','PeerJ','PsyArXiv','PaleorXiv','AfricArXiv','EcoEvoRxiv')"/>
<xsl:variable name="lower-exceptions" select="('and', 'or', 'of', 'the', 'in', 'on', 'with', 'a', 'an')"/>
<xsl:variable name="words" select="tokenize($input,'\s+')" />
<xsl:variable name="processed-words">
<xsl:for-each select="$words">
<xsl:variable name="val" select="."/>
<xsl:choose>
<xsl:when test="position()=1 and not(lower-case(.)=$case-exceptions) and not(upper-case(.)=$upper-exceptions)">
<xsl:value-of select="concat(upper-case(substring(.,1,1)),lower-case(substring(.,2)))"/>
</xsl:when>
<xsl:when test="upper-case(.)=$upper-exceptions">
<xsl:value-of select="upper-case(.)"/>
</xsl:when>
<xsl:when test="some $example in $case-exceptions satisfies (lower-case($example)=lower-case($val))">
<xsl:value-of select="$case-exceptions[lower-case(.)=lower-case($val)]"/>
</xsl:when>
<xsl:when test="lower-case(.)=($lower-exceptions)">
<xsl:value-of select="lower-case(.)"/>
</xsl:when>
<xsl:when test="string-length(.)=1">
<xsl:value-of select="upper-case(.)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(upper-case(substring(.,1,1)),lower-case(substring(.,2)))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:sequence select="string-join($processed-words,' ')" />
</xsl:function>

<xsl:template match="*|@*|text()|comment()|processing-instruction()">
<xsl:copy>
Expand Down Expand Up @@ -799,7 +833,11 @@
<xsl:variable name="mixed-citation-round-3">
<xsl:apply-templates select="$mixed-citation-round-2" mode="mixed-citation-round-3"/>
</xsl:variable>
<xsl:apply-templates select="$mixed-citation-round-3" mode="mixed-citation-round-4"/>
<xsl:variable name="mixed-citation-round-4">
<xsl:apply-templates select="$mixed-citation-round-3" mode="mixed-citation-round-4"/>
</xsl:variable>
<xsl:apply-templates select="$mixed-citation-round-4" mode="mixed-citation-round-5"/>

</xsl:template>

<!-- Introduces author person-groups into refs when they are missing-->
Expand Down Expand Up @@ -943,6 +981,39 @@
</xsl:copy>
</xsl:template>

<!-- Fixes mistagged and all caps source elements -->
<xsl:template xml:id="ref-source-fixes" mode="mixed-citation-round-4" match="mixed-citation//source">
<xsl:choose>
<xsl:when test="matches(lower-case(.),'^in\s')">
<xsl:choose>
<xsl:when test="(ancestor::mixed-citation/@publication-type=('preprint','journal','other')) and upper-case(.)=.">
<xsl:text>In </xsl:text>
<xsl:copy>
<xsl:value-of select="e:toTitleCase(substring-after(.,' '))"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:text>In </xsl:text>
<xsl:copy>
<xsl:value-of select="substring-after(.,' ')"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="(ancestor::mixed-citation/@publication-type=('preprint','journal','other')) and upper-case(.)=.">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:value-of select="e:toTitleCase(.)"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<!-- Add a CC-BY biorender statement for CC0 RPs -->
<xsl:template xml:id="biorender-permissions" match="article[front//permissions/license/@xlink:href[contains(lower-case(.),'creativecommons.org/publicdomain/zero/')]]//*[caption[contains(lower-case(.),'biorender')]]">
Expand Down
2 changes: 2 additions & 0 deletions test/tests/preprint-changes/all/input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
<ref id="c4"><label>4.</label><mixed-citation publication-type="book"><string-name><given-names>A.</given-names> <surname>Nagy</surname></string-name>, <string-name><given-names>M.</given-names> <surname>Gertsenstein</surname></string-name>, <string-name><given-names>K.</given-names> <surname>Vintersten</surname></string-name>, … and <string-name><given-names>R.</given-names> <surname>Behringer</surname></string-name>, <chapter-title>Manipulating the mouse embryo: a laboratory manual</chapter-title> (<publisher-name>Cold Spring Harbor Laboratory Press Cold Spring Harbor</publisher-name>, NY:, <year>2003</year>), vol. <volume>10</volume>.</mixed-citation></ref>
<ref id="c5"><label>5.</label><mixed-citation publication-type="book"><string-name><given-names>J. M.</given-names> <surname>Glynn</surname></string-name>, <string-name><given-names>T. G.</given-names> <surname>Cotter</surname></string-name>, <string-name><given-names>D. R.</given-names> <surname>Green</surname></string-name> (<year>1992</year>) <article-title>Apoptosis induced by actinomycin D, camptothecin or aphidicolin can occur in all phases of the cell cycle</article-title>. (<publisher-loc>Portland</publisher-loc> <publisher-name>Press Ltd</publisher-name>.).</mixed-citation></ref>
<ref id="c6"><label>6.</label><mixed-citation publication-type="journal"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal> (<year>2021</year>) <article-title>Unveiling the sensory and interneuronal pathways of the neuroendocrine connectome in Drosophila</article-title>. <source>Elife</source> <volume>10</volume>:<fpage>e65745</fpage></mixed-citation></ref>
<ref id="c7"><label>7.</label><mixed-citation publication-type="journal"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal> (<year>2021</year>) <article-title>Unveiling the sensory and interneuronal pathways of the neuroendocrine connectome in Drosophila</article-title>. <source>ELIFE</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
<ref id="c8"><label>8.</label><mixed-citation publication-type="journal"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal> (<year>2021</year>) <article-title>..</article-title>. <source>PLANT PHYSIOLOGY</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
</ref-list>
</back>
</article>
2 changes: 2 additions & 0 deletions test/tests/preprint-changes/all/output.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
<ref id="c4"><label>4.</label><mixed-citation publication-type="book"><person-group person-group-type="author"><string-name><given-names>A.</given-names> <surname>Nagy</surname></string-name>, <string-name><given-names>M.</given-names> <surname>Gertsenstein</surname></string-name>, <string-name><given-names>K.</given-names> <surname>Vintersten</surname></string-name>, <etal>…</etal> <string-name><given-names>R.</given-names> <surname>Behringer</surname></string-name></person-group>, <source>Manipulating the mouse embryo: a laboratory manual</source> (<publisher-name>Cold Spring Harbor Laboratory Press Cold Spring Harbor</publisher-name>, NY:, <year>2003</year>), vol. <volume>10</volume>.</mixed-citation></ref>
<ref id="c5"><label>5.</label><mixed-citation publication-type="book"><person-group person-group-type="author"><string-name><given-names>J. M.</given-names> <surname>Glynn</surname></string-name>, <string-name><given-names>T. G.</given-names> <surname>Cotter</surname></string-name>, <string-name><given-names>D. R.</given-names> <surname>Green</surname></string-name></person-group> (<year>1992</year>) <source>Apoptosis induced by actinomycin D, camptothecin or aphidicolin can occur in all phases of the cell cycle</source>. (<publisher-loc>Portland</publisher-loc> <publisher-name>Press Ltd</publisher-name>.).</mixed-citation></ref>
<ref id="c6"><label>6.</label><mixed-citation publication-type="journal"><person-group person-group-type="author"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal></person-group> (<year>2021</year>) <article-title>Unveiling the sensory and interneuronal pathways of the neuroendocrine connectome in Drosophila</article-title>. <source>Elife</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
<ref id="c7"><label>7.</label><mixed-citation publication-type="journal"><person-group person-group-type="author"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal></person-group> (<year>2021</year>) <article-title>Unveiling the sensory and interneuronal pathways of the neuroendocrine connectome in Drosophila</article-title>. <source>eLife</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
<ref id="c8"><label>8.</label><mixed-citation publication-type="journal"><person-group person-group-type="author"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal></person-group> (<year>2021</year>) <article-title>..</article-title>. <source>Plant Physiology</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
</ref-list>
</back>
</article>
8 changes: 8 additions & 0 deletions test/tests/preprint-changes/ref-source-fixes/input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--Testing template with id: ref-source-fixes-->
<ref-list>
<ref id="c4"><label>4.</label><mixed-citation publication-type="other"><string-name><surname>Claus</surname> <given-names>S</given-names></string-name>, <etal>et al</etal> (<year>2021</year>) <article-title>..</article-title>. <source>AGAINST METHOD</source></mixed-citation></ref>
<ref id="c5"><label>5.</label><mixed-citation publication-type="journal"><string-name><surname>Claus</surname> <given-names>S</given-names></string-name>, <etal>et al</etal> (<year>2021</year>) <article-title>..</article-title>. <source>PLOS ONE</source></mixed-citation></ref>
<ref id="c6"><label>6.</label><mixed-citation publication-type="preprint"><string-name><surname>Claus</surname> <given-names>S</given-names></string-name>, <etal>et al</etal> (<year>2021</year>) <article-title>..</article-title>. <source>BIORXIV</source></mixed-citation></ref>
<ref id="c7"><label>7.</label><mixed-citation publication-type="journal"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal> (<year>2021</year>) <article-title>Unveiling the sensory and interneuronal pathways of the neuroendocrine connectome in Drosophila</article-title>. <source>ELIFE</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
<ref id="c8"><label>8.</label><mixed-citation publication-type="journal"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal> (<year>2021</year>) <article-title>..</article-title>. <source>PLANT PHYSIOLOGY</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
</ref-list>
8 changes: 8 additions & 0 deletions test/tests/preprint-changes/ref-source-fixes/output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--Testing template with id: ref-source-fixes-->
<ref-list>
<ref id="c4"><label>4.</label><mixed-citation publication-type="other"><person-group person-group-type="author"><string-name><surname>Claus</surname> <given-names>S</given-names></string-name>, <etal>et al</etal></person-group> (<year>2021</year>) <article-title>..</article-title>. <source>Against Method</source></mixed-citation></ref>
<ref id="c5"><label>5.</label><mixed-citation publication-type="journal"><person-group person-group-type="author"><string-name><surname>Claus</surname> <given-names>S</given-names></string-name>, <etal>et al</etal></person-group> (<year>2021</year>) <article-title>..</article-title>. <source>PLOS One</source></mixed-citation></ref>
<ref id="c6"><label>6.</label><mixed-citation publication-type="preprint"><person-group person-group-type="author"><string-name><surname>Claus</surname> <given-names>S</given-names></string-name>, <etal>et al</etal></person-group> (<year>2021</year>) <article-title>..</article-title>. <source>bioRxiv</source></mixed-citation></ref>
<ref id="c7"><label>7.</label><mixed-citation publication-type="journal"><person-group person-group-type="author"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal></person-group> (<year>2021</year>) <article-title>Unveiling the sensory and interneuronal pathways of the neuroendocrine connectome in Drosophila</article-title>. <source>eLife</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
<ref id="c8"><label>8.</label><mixed-citation publication-type="journal"><person-group person-group-type="author"><string-name><surname>Huckesfeld</surname> <given-names>S</given-names></string-name>, <etal>et al</etal></person-group> (<year>2021</year>) <article-title>..</article-title>. <source>Plant Physiology</source> <volume>10</volume>:<elocation-id>e65745</elocation-id></mixed-citation></ref>
</ref-list>
4 changes: 4 additions & 0 deletions test/xspec/preprint-changes.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
<x:context href="../tests/preprint-changes/find-and-tag-preprint-refs/input.xml"/>
<x:expect label="Testing the template: find-and-tag-preprint-refs" href="../tests/preprint-changes/find-and-tag-preprint-refs/output.xml"/>
</x:scenario>
<x:scenario label="ref-source-fixes">
<x:context href="../tests/preprint-changes/ref-source-fixes/input.xml"/>
<x:expect label="Testing the template: ref-source-fixes" href="../tests/preprint-changes/ref-source-fixes/output.xml"/>
</x:scenario>
<x:scenario label="biorender-permissions">
<x:context href="../tests/preprint-changes/biorender-permissions/input.xml"/>
<x:expect label="Testing the template: biorender-permissions" href="../tests/preprint-changes/biorender-permissions/output.xml"/>
Expand Down

0 comments on commit d1cd162

Please sign in to comment.