How can I customize the "export as csv" function in geonetwork?

90 Views Asked by At

I would like to customize the export as csv function in Geonetwork 3.8.1.

I know that the file to edit is the tpl-csv.xsl which, in my case, is located here

geonetwork/WEB-INF/data/config/schema_plugins/iso19115-3.2018/layout/tpl-csv.xsl

The output I would like to have is the following one:

"title","cloud coverage","category","date-creation" "S2A_MSIL1C_20151127T103352_N0204_R108_T32TLS_20151127T103440","36.6172","dataset","2015-11-27T10:34:40"

I did some test but I'm only able to have

"schema","uuid","id","cit:title","gco:Real","category","date-creation" "iso19115-3.2018","89d82f0a-051e-11ea-80ac-02000a08f492","1155","S2A_MSIL1C_20151127T103352_N0204_R108_T32TLS_20151127T103440","36.6172","dataset","2015-11-27T10:34:40",

How can I edit in a more correct way the tpl-csv.xsl?

1

There are 1 best solutions below

0
sylar_80 On

I found the solution to customize the output of the EXPORT(CSV) function.

These are the two files to consider:

geonetwork/WEB-INF/data/config/schema_plugins/iso19115-3.2018/layout/tpl-csv.xsl
geonetwork/xslt/services/csv/csv-search.xsl

In the first one, as suggested to me by @josegar74, you have to add a similar line in between the abstract and category elements: myfieldvalue In my case I inserted:

<title><xsl:copy-of select="mdb:identificationInfo/*/mri:citation/*/cit:title"/></title>
<cloud_coverage_percentage><xsl:copy-of select="mdb:contentInfo/mrc:MD_ImageDescription/mrc:cloudCoverPercentage/gco:Real"/></cloud_coverage_percentage>

About cloud coverage percentage in particular, please remember to add the namespace in the header because it is missing:

xmlns:mrc="http://standards.iso.org/iso/19115/-3/mrc/2.0"

Then aI commented all the other lines I'm not interested in but:

<xsl:copy-of select="gn:info"/>

About the second file, csv-search.xsl, I found that to avoid printing automatically the 3 columns:"schema","uuid","id", you have to comment the following lines:

<xsl:text>"schema"</xsl:text>
<xsl:value-of select="$sep"/>
<xsl:text>"uuid"</xsl:text>
<xsl:value-of select="$sep"/>
<xsl:text>"id"</xsl:text><xsl:value-of select="$sep"/>

and

<xsl:value-of select="concat('&quot;', $metadata/geonet:info/schema, '&quot;', $sep,
                  '&quot;', $metadata/geonet:info/uuid, '&quot;', $sep,
                  '&quot;', $metadata/geonet:info/id, '&quot;', $sep)"/>

In this way I had the possibility to get the desired output:

"uuid","title","cloud_coverage_percentage","category","date-creation" "c94da70e-066e-11ea-aa22-02000a08f492","S2A_MSIL1C_20180320T101021_N0206_R022_T33TUM_20180320T122057","36.0368","dataset","2018-03-20T12:20:57", "7caf22dc-066f-11ea-a038-02000a08f492","S2A_MSIL1C_20180320T101021_N0206_R022_T33TVN_20180320T122057","100.0","dataset","2018-03-20T12:20:57",

If you do not want to see the last comma after the last value (date-creation in my case) you can add a small piece of code at the end of the file:

comment the line
`<xsl:value-of select="$sep"/>` (l.185)

add the following lines of codes:

<xsl:if test="position() != last()">
    <xsl:value-of select="$sep"/>
</xsl:if>

I will try to open a pull request for this.

I hope this additional information could be useful for someone else.