Skip to content

Commit a7c0dee

Browse files
Standard / Formatter / Citation improvements (geonetwork#7434)
* Standard / Formatter / Citation improvements * Improve list of contact (when multiple individual names or when same contact with multiple roles) * Cleanup layout (avoid extra space/add missing ones) * Add formatter parameter to customize author and publisher roles (eg. http://localhost:8080/geonetwork/srv/api/records/uuid/formatters/citation?format=text&authorRoles=author,processor&publisherRoles=publisher,custodian) * Add test * Update services/src/test/java/org/fao/geonet/api/records/formatters/FormatterApiTest.java Co-authored-by: Jose García <[email protected]> * Jose's feedbacks. --------- Co-authored-by: Jose García <[email protected]>
1 parent d88a609 commit a7c0dee

File tree

19 files changed

+3000
-124
lines changed

19 files changed

+3000
-124
lines changed

core/src/test/java/org/fao/geonet/AbstractCoreIntegrationTest.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,21 @@ public MockHttpSession loginAsAnonymous() {
294294
}
295295

296296

297+
private static Element getSample(String resource) throws IOException, JDOMException {
298+
final URL resourceUrl = AbstractCoreIntegrationTest.class.getResource(resource);
299+
return Xml.loadStream(resourceUrl.openStream());
300+
}
301+
297302
public Element getSampleMetadataXml() throws IOException, JDOMException {
298-
final URL resource = AbstractCoreIntegrationTest.class.getResource("kernel/valid-metadata.iso19139.xml");
299-
return Xml.loadStream(resource.openStream());
303+
return getSample("kernel/valid-metadata.iso19139.xml");
304+
}
305+
306+
public Element getSampleISO19139MetadataXml() throws IOException, JDOMException {
307+
return getSample("kernel/metadata.iso19139.xml");
308+
}
309+
310+
public Element getSampleISO19115MetadataXml() throws IOException, JDOMException {
311+
return getSample("kernel/metadata.iso19115-3.xml");
300312
}
301313

302314
/**

core/src/test/resources/org/fao/geonet/kernel/metadata.iso19115-3.xml

+1,555
Large diffs are not rendered by default.

core/src/test/resources/org/fao/geonet/kernel/metadata.iso19139.xml

+1,054
Large diffs are not rendered by default.

schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/citation/base.xsl

+42-50
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,57 @@
1818
<xsl:import href="../../layout/utility-tpl-multilingual.xsl"/>
1919
<xsl:import href="../../layout/utility-fn.xsl"/>
2020

21-
<xsl:template name="get-iso19115-3.2018-citation">
22-
<xsl:param name="metadata" as="node()"/>
23-
<xsl:param name="language" as="xs:string"/>
24-
25-
<xsl:variable name="langId"
26-
select="gn-fn-iso19115-3.2018:getLangId($metadata, $language)"/>
21+
<xsl:function name="gn-fn-iso19115-3.2018:get-author-list">
22+
<xsl:param name="authors" as="node()*"/>
23+
<xsl:param name="langId" as="xs:string"/>
2724

28-
<!-- Who is the creator of the data set? This can be an individual, a group of individuals, or an organization. -->
29-
<xsl:variable name="authorRoles"
30-
select="('custodian', 'author')"/>
31-
<xsl:variable name="authors"
32-
select="$metadata/mdb:identificationInfo/*/mri:pointOfContact/
33-
*[cit:role/*/@codeListValue = $authorRoles]"/>
34-
<xsl:variable name="authorsNameAndOrgList">
25+
<xsl:variable name="authorsNameAndOrgListTmp"
26+
as="node()*">
3527
<xsl:for-each select="$authors">
3628
<author>
3729
<xsl:variable name="name"
38-
select=".//cit:individual/*/cit:name[1]"/>
39-
40-
<xsl:for-each select="$name">
41-
<xsl:call-template name="get-iso19115-3.2018-localised">
42-
<xsl:with-param name="langId" select="$langId"/>
43-
</xsl:call-template>
44-
</xsl:for-each>
45-
<xsl:if test="normalize-space($name) != ''">(</xsl:if>
30+
select=".//cit:individual/*/cit:name"/>
31+
32+
<xsl:variable name="listOfNames">
33+
<xsl:for-each select="$name">
34+
<xsl:call-template name="get-iso19115-3.2018-localised">
35+
<xsl:with-param name="langId" select="$langId"/>
36+
</xsl:call-template>
37+
<xsl:if test="position() != last()">, </xsl:if>
38+
</xsl:for-each>
39+
</xsl:variable>
40+
41+
<xsl:value-of select="$listOfNames"/>
42+
<xsl:if test="normalize-space($listOfNames) != ''"> (</xsl:if>
4643
<xsl:for-each select="cit:party/*/cit:name">
4744
<xsl:call-template name="get-iso19115-3.2018-localised">
4845
<xsl:with-param name="langId" select="$langId"/>
4946
</xsl:call-template>
5047
</xsl:for-each>
51-
<xsl:if test="normalize-space($name) != ''">)</xsl:if>
48+
<xsl:if test="normalize-space($listOfNames) != ''">)</xsl:if>
5249
</author>
5350
</xsl:for-each>
5451
</xsl:variable>
5552

53+
<xsl:for-each-group select="$authorsNameAndOrgListTmp" group-by=".">
54+
<xsl:copy-of select="."/>
55+
</xsl:for-each-group>
56+
</xsl:function>
57+
58+
<xsl:template name="get-iso19115-3.2018-citation">
59+
<xsl:param name="metadata" as="node()"/>
60+
<xsl:param name="language" as="xs:string"/>
61+
62+
<xsl:variable name="langId"
63+
select="gn-fn-iso19115-3.2018:getLangId($metadata, $language)"/>
64+
65+
<xsl:variable name="authors"
66+
select="$metadata/mdb:identificationInfo/*/mri:pointOfContact/
67+
*[cit:role/*/@codeListValue = $authorRolesList]"/>
68+
<xsl:variable name="authorsNameAndOrgList"
69+
select="gn-fn-iso19115-3.2018:get-author-list($authors, $langId)"/>
70+
71+
5672
<!-- What name is the data set called? -->
5773
<xsl:variable name="title"
5874
select="$metadata/mdb:identificationInfo/*/mri:citation/*/cit:title"/>
@@ -84,36 +100,12 @@
84100

85101
<xsl:variable name="lastPublicationDate"
86102
select="$publicationDates[1]"/>
87-
88-
<!-- What entity is responsible for producing and/or distributing the data set? Also, is there a physical location associated with the publisher? -->
89-
<xsl:variable name="publisherRoles"
90-
select="('publisher')"/>
91-
<xsl:variable name="publishers"
103+
<xsl:variable name="publishers" as="node()*"
92104
select="$metadata/mdb:identificationInfo/*/mri:pointOfContact/
93-
*[cit:role/*/@codeListValue = $publisherRoles]"/>
94-
95-
<xsl:variable name="publishersNameAndOrgList">
96-
<xsl:for-each select="$publishers">
97-
<author>
98-
<xsl:variable name="name"
99-
select=".//cit:individual/*/cit:name[1]"/>
100-
101-
<xsl:for-each select="$name">
102-
<xsl:call-template name="get-iso19115-3.2018-localised">
103-
<xsl:with-param name="langId" select="$langId"/>
104-
</xsl:call-template>
105-
</xsl:for-each>
106-
<xsl:if test="normalize-space($name) != ''">(</xsl:if>
107-
<xsl:for-each select="cit:party/*/cit:name">
108-
<xsl:call-template name="get-iso19115-3.2018-localised">
109-
<xsl:with-param name="langId" select="$langId"/>
110-
</xsl:call-template>
111-
</xsl:for-each>
112-
<xsl:if test="normalize-space($name) != ''">)</xsl:if>
113-
</author>
114-
</xsl:for-each>
115-
</xsl:variable>
105+
*[cit:role/*/@codeListValue = $publisherRolesList]"/>
116106

107+
<xsl:variable name="publishersNameAndOrgList" as="node()*"
108+
select="gn-fn-iso19115-3.2018:get-author-list($publishers, $langId)"/>
117109

118110
<!-- Electronic Retrieval Location -->
119111
<xsl:variable name="doiInResourceIdentifier"

schemas/iso19115-3.2018/src/main/plugin/iso19115-3.2018/formatter/citation/common.xsl

+35-19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
<xsl:param name="format"
1616
select="'html'"/>
1717

18+
<!-- Who is the creator of the data set? This can be an individual, a group of individuals, or an organization. -->
19+
<xsl:param name="authorRoles"
20+
select="'custodian,author'"/>
21+
<xsl:variable name="authorRolesList"
22+
select="tokenize($authorRoles, ',')"/>
23+
24+
<!-- What entity is responsible for producing and/or distributing the data set? Also, is there a physical location associated with the publisher? -->
25+
<xsl:param name="publisherRoles"
26+
select="'publisher'"/>
27+
<xsl:variable name="publisherRolesList"
28+
select="tokenize($publisherRoles, ',')"/>
29+
1830
<xsl:variable name="formats" as="node()*">
1931
<format key="html"/>
2032
<format key="text"/>
@@ -36,33 +48,35 @@
3648
select="count(authorsNameAndOrgList/*) > 0"/>
3749
<xsl:variable name="hasPublisher"
3850
select="count(publishersNameAndOrgList/*) > 0"/>
39-
<textResponse>
40-
<xsl:value-of select="concat(
51+
<textResponse><xsl:value-of select="normalize-space(concat(
4152
(if ($hasAuthor)
4253
then string-join(authorsNameAndOrgList/*, ', ')
4354
else ''),
55+
(if ($hasAuthor)
56+
then ' '
57+
else ''),
4458
(if (lastPublicationDate != '')
45-
then concat(' (', substring(lastPublicationDate, 1, 4), '). ')
59+
then concat('(', substring(lastPublicationDate, 1, 4), '). ')
4660
else if ($hasAuthor) then '. ' else ''),
47-
translatedTitle,
61+
normalize-space(translatedTitle),
4862
'. ',
4963
(if ($hasPublisher)
5064
then concat(string-join(publishersNameAndOrgList/*, ', '), '. ')
5165
else ''),
52-
if (doiUrl != '') then doiUrl else landingPageUrl)"/>
66+
if (doiUrl != '') then doiUrl else landingPageUrl))"/>
5367
</textResponse>
5468
</xsl:template>
5569

5670

5771
<xsl:template mode="citation" match="citation[lower-case($format) = 'bibtex']">
5872
<!-- https://en.wikipedia.org/wiki/BibTeX -->
5973
<textResponse>@data{<xsl:value-of select="uuid"/>,
60-
author = {<xsl:value-of select="string-join(authorsNameAndOrgList/*, ' and ')"/>},
61-
publisher = {<xsl:value-of select="string-join(publishersNameAndOrgList/*, ' and ')"/>},
62-
title = {<xsl:value-of select="translatedTitle"/>},
63-
<xsl:if test="lastPublicationDate != ''">year = {<xsl:value-of select="substring(lastPublicationDate, 1, 4)"/>},</xsl:if>
64-
<xsl:if test="doi != ''">doi = {<xsl:value-of select="doi"/>},</xsl:if>
65-
url = {<xsl:value-of select="if (doiUrl != '') then doiUrl else landingPageUrl"/>}
74+
author = {<xsl:value-of select="normalize-space(string-join(authorsNameAndOrgList/*, ', '))"/>},
75+
publisher = {<xsl:value-of select="normalize-space(string-join(publishersNameAndOrgList/*, ', '))"/>},
76+
title = {<xsl:value-of select="normalize-space(translatedTitle)"/>},
77+
<xsl:if test="lastPublicationDate != ''">year = {<xsl:value-of select="substring(lastPublicationDate, 1, 4)"/>},</xsl:if>
78+
<xsl:if test="doi != ''">doi = {<xsl:value-of select="doi"/>},</xsl:if>
79+
url = {<xsl:value-of select="if (doiUrl != '') then doiUrl else landingPageUrl"/>}
6680
}</textResponse>
6781
</xsl:template>
6882

@@ -73,12 +87,12 @@
7387
<!-- TODO: add support for MAP, DBASE, CTLG, AGGR? -->
7488
<xsl:text>TY - </xsl:text><xsl:value-of select="'DATA'"/><xsl:text>&#13;&#10;</xsl:text>
7589
<xsl:for-each select="authorsNameAndOrgList/*[. != '']">
76-
<xsl:text>AU - </xsl:text><xsl:value-of select="."/><xsl:text>&#13;&#10;</xsl:text>
90+
<xsl:text>AU - </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>&#13;&#10;</xsl:text>
7791
</xsl:for-each>
78-
<xsl:text>TI - </xsl:text><xsl:value-of select="translatedTitle"/><xsl:text>&#13;&#10;</xsl:text>
92+
<xsl:text>TI - </xsl:text><xsl:value-of select="normalize-space(translatedTitle)"/><xsl:text>&#13;&#10;</xsl:text>
7993
<!-- TODO: LA, ET -->
8094
<xsl:for-each select="publishersNameAndOrgList/*[. != '']">
81-
<xsl:text>PB - </xsl:text><xsl:value-of select="."/><xsl:text>&#13;&#10;</xsl:text>
95+
<xsl:text>PB - </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>&#13;&#10;</xsl:text>
8296
</xsl:for-each>
8397
<xsl:for-each select="keyword[. != '']">
8498
<xsl:text>KW - </xsl:text><xsl:value-of select="."/><xsl:text>&#13;&#10;</xsl:text>
@@ -114,23 +128,24 @@
114128
else if ($hasAuthor) then '.'
115129
else ''"/>
116130

117-
<div><xsl:copy-of select="translatedTitle/(text()|*)"/>.</div>
131+
<span><xsl:copy-of select="translatedTitle/(text()|*)"/>.</span>
118132

119133
<xsl:call-template name="citation-contact">
120134
<xsl:with-param name="contact" select="publishersNameAndOrgList"/>
121135
</xsl:call-template>
122-
<br/>
136+
<br></br>
137+
123138
<xsl:variable name="url"
124139
select="if (doiUrl != '') then doiUrl else landingPageUrl"/>
125140
<a href="{$url}">
126141
<xsl:value-of select="$url"/>
127142
</a>
128-
<br/>
143+
<br></br>
129144

130145
<xsl:if test="additionalCitation != ''">
131-
<br/>
146+
<br></br>
132147
<em><xsl:value-of select="$schemaStrings/citationAdditional"/></em>
133-
<br/>
148+
<br></br>
134149
<xsl:value-of select="additionalCitation"/>
135150
</xsl:if>
136151
</p>
@@ -150,6 +165,7 @@
150165
</span>
151166
</xsl:for-each>
152167
<xsl:if test="position() != last()">, </xsl:if>
168+
<xsl:if test="position() = last()">&#160;</xsl:if>
153169
</xsl:for-each>
154170
</xsl:template>
155171
</xsl:stylesheet>

schemas/iso19139/src/main/plugin/iso19139/formatter/citation/base.xsl

+28-42
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,12 @@
2222
<xsl:import href="../../layout/utility-tpl-multilingual.xsl"/>
2323
<xsl:import href="../../layout/utility-fn.xsl"/>
2424

25-
<xsl:template name="get-iso19139-citation">
26-
<xsl:param name="metadata" as="node()"/>
27-
<xsl:param name="language" as="xs:string"/>
28-
29-
<xsl:variable name="langId"
30-
select="gn-fn-iso19139:getLangId($metadata, $language)"/>
25+
<xsl:function name="gn-fn-iso19139:get-author-list">
26+
<xsl:param name="authors" as="node()*"/>
27+
<xsl:param name="langId" as="xs:string"/>
3128

32-
33-
<!-- Who is the creator of the data set? This can be an individual, a group of individuals, or an organization. -->
34-
<xsl:variable name="authorRoles"
35-
select="('author')"/>
36-
<xsl:variable name="authors"
37-
select="$metadata/gmd:identificationInfo/*/gmd:pointOfContact/
38-
*[gmd:role/*/@codeListValue = $authorRoles]"/>
39-
<xsl:variable name="authorsNameAndOrgList">
29+
<xsl:variable name="authorsNameAndOrgListTmp"
30+
as="node()*">
4031
<xsl:for-each select="$authors">
4132
<author>
4233
<xsl:variable name="name"
@@ -58,6 +49,25 @@
5849
</xsl:for-each>
5950
</xsl:variable>
6051

52+
<xsl:for-each-group select="$authorsNameAndOrgListTmp" group-by=".">
53+
<xsl:copy-of select="."/>
54+
</xsl:for-each-group>
55+
</xsl:function>
56+
57+
58+
<xsl:template name="get-iso19139-citation">
59+
<xsl:param name="metadata" as="node()"/>
60+
<xsl:param name="language" as="xs:string"/>
61+
62+
<xsl:variable name="langId"
63+
select="gn-fn-iso19139:getLangId($metadata, $language)"/>
64+
65+
<xsl:variable name="authors"
66+
select="$metadata/gmd:identificationInfo/*/gmd:pointOfContact/
67+
*[gmd:role/*/@codeListValue = $authorRolesList]"/>
68+
<xsl:variable name="authorsNameAndOrgList" as="node()*"
69+
select="gn-fn-iso19139:get-author-list($authors, $langId)"/>
70+
6171
<!-- What name is the data set called? -->
6272
<xsl:variable name="title"
6373
select="$metadata/gmd:identificationInfo/*/gmd:citation/*/gmd:title"/>
@@ -90,35 +100,11 @@
90100
<xsl:variable name="lastPublicationDate"
91101
select="$publicationDates[1]"/>
92102

93-
<!-- What entity is responsible for producing and/or distributing the data set? Also, is there a physical location associated with the publisher? -->
94-
<xsl:variable name="publisherRoles"
95-
select="('publisher')"/>
96103
<xsl:variable name="publishers"
97104
select="$metadata/gmd:identificationInfo/*/gmd:pointOfContact/
98-
*[gmd:role/*/@codeListValue = $publisherRoles]"/>
99-
100-
<xsl:variable name="publishersNameAndOrgList">
101-
<xsl:for-each select="$publishers">
102-
<author>
103-
<xsl:variable name="name"
104-
select=".//gmd:individualName[1]"/>
105-
106-
<xsl:for-each select="$name">
107-
<xsl:call-template name="localised">
108-
<xsl:with-param name="langId" select="$langId"/>
109-
</xsl:call-template>
110-
</xsl:for-each>
111-
<xsl:if test="normalize-space($name) != ''">(</xsl:if>
112-
<xsl:for-each select=".//gmd:organisationName">
113-
<xsl:call-template name="localised">
114-
<xsl:with-param name="langId" select="$langId"/>
115-
</xsl:call-template>
116-
</xsl:for-each>
117-
<xsl:if test="normalize-space($name) != ''">)</xsl:if>
118-
</author>
119-
</xsl:for-each>
120-
</xsl:variable>
121-
105+
*[gmd:role/*/@codeListValue = $publisherRolesList]"/>
106+
<xsl:variable name="publishersNameAndOrgList" as="node()*"
107+
select="gn-fn-iso19139:get-author-list($publishers, $langId)"/>
122108

123109
<!-- Electronic Retrieval Location -->
124110
<xsl:variable name="doiInResourceIdentifier"
@@ -129,7 +115,7 @@
129115
or contains(*/@xlink:href, 'doi.org')]/*/(@xlink:href|text()))[1]"/>
130116

131117
<xsl:variable name="doiProtocolRegex"
132-
select="'(DOI|WWW:LINK-1.0-http--metadata-URL)'"/>
118+
select="'(DOI|WWW:LINK-1.0-http--metadata-URL)'"/>
133119

134120
<xsl:variable name="doiInOnline"
135121
select="//gmd:distributionInfo//gmd:onLine/*[

0 commit comments

Comments
 (0)