ecolabdata / ecospheres-isomorphe

Une application pour appliquer des transformations XML aux catalogues Geonetwork du MTECT.
0 stars 0 forks source link

XSL parameters #33

Closed streino closed 2 weeks ago

streino commented 3 weeks ago

Some XSL will require parameters set by the user. Cf eg https://ecospheres.gitbook.io/recommandations-iso-dcat/adaptation-des-metadonnees-iso-19139-pour-faciliter-la-transformation-en-dcat/rendre-les-distributions-identifiables would require some sort of pattern matching dependent on the targeted catalog.

abulte commented 3 weeks ago

Do we want to handle N parameters? And configure how many (and which) parameters a transformation expects?

Or maybe we start with one unnamed parameter. But we still need to configure which transformation expects a parameter.

streino commented 3 weeks ago

Do we want to handle N parameters?

Not sure yet how many params we'll need. We can start with one if we want, I expect it'll be the most frequent case.

And configure how many (and which) parameters a transformation expects?

XSLT params are children of the top-level xsl:stylesheet root. Best way IMO is get those from the parse tree. We get the name and default value that way. Maybe lxml even has some specific way to get those, since it has to know how to set them.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  ...
  <xsl:param name="myparam" select="'foo'"/>
  ...
abulte commented 2 weeks ago

This could be a good test case (change-language with a parameter):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
                xmlns:gco="http://www.isotc211.org/2005/gco"
                xmlns:gmd="http://www.isotc211.org/2005/gmd"
                xmlns:geonet="http://www.fao.org/geonetwork"
                exclude-result-prefixes="#all">

  <xsl:param name="language" select="'eng'"/>

  <xsl:strip-space elements="*"/>

  <xsl:template match="/gmd:MD_Metadata/gmd:language/gco:CharacterString/text()">
    <xsl:value-of select="$language"/>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
streino commented 2 weeks ago

This could be a good test case (change-language with a parameter):

Yes ! That was the idea ;) Nitpick, <xsl:strip-space elements="*"/> usually stays at the top.