Skip to content

Commit

Permalink
make the context of the included schema files clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
pahjbo committed Feb 8, 2024
1 parent 4d27ef7 commit 90aaffc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 39 deletions.
1 change: 1 addition & 0 deletions tools/xslt/common-binding.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vo-dml="http://www.ivoa.net/xml/VODML/v1">

<!-- this stylesheet requires that binding files have been read in -->
<xsl:include href="common.xsl"/>
<xsl:include href="common-structure-functions.xsl"/>

Expand Down
11 changes: 1 addition & 10 deletions tools/xslt/common-structure-functions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ note - only define functions in here as it is included in the schematron rules
xmlns:vo-dml="http://www.ivoa.net/xml/VODML/v1">
<xsl:key name="ellookup" match="//*[vodml-id]" use="concat(ancestor::vo-dml:model/name,':',vodml-id)"/>

<!-- this function does not rely on vodml-id being present -->
<xsl:function name="vf:asvodmlref" as="xsd:string">
<xsl:param name="el" as="element()"/>
<xsl:value-of select="concat($el/ancestor::vo-dml:model/name,':',string-join($el/ancestor-or-self::*/name[not(../name() = 'vo-dml:model')], '.'))"/>
</xsl:function>

<xsl:function name="vf:nameFromVodmlref" as="xsd:string">
<xsl:param name="vodml-ref" as="xsd:string"/>
<xsl:value-of select="tokenize($vodml-ref,'[\.:]')[last()]"/>
</xsl:function>
<xsl:include href="common_functions.xsl"/>

<!-- does the vodml-ref exist? -->
<xsl:function name="vf:vo-dml-ref-exists" as="xsd:boolean">
Expand Down
31 changes: 2 additions & 29 deletions tools/xslt/common.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
>

<!--
This XSLT script contains common xsl:templates used by other XSLT scripts.
This XSLT script contains common templates that depend only on a single instance of a VO-DML file being in scope.
-->

<xsl:variable name="cr">
Expand All @@ -26,21 +26,6 @@
<xsl:variable name='lt'><xsl:text disable-output-escaping="yes">&lt;</xsl:text></xsl:variable>
<xsl:variable name='gt'><xsl:text disable-output-escaping="yes">&gt;</xsl:text></xsl:variable>


<xsl:function name="vf:upperFirst" as="xsd:string">
<xsl:param name="s" as="xsd:string"/>
<xsl:value-of select="concat(upper-case(substring($s,1,1)),substring($s,2))"/>
</xsl:function>
<xsl:function name="vf:lowerFirst" as="xsd:string">
<xsl:param name="s" as="xsd:string"/>
<xsl:value-of select="concat(lower-case(substring($s,1,1)),substring($s,2))"/>
</xsl:function>

<xsl:function name="vf:capitalize">
<xsl:param name="name"/>
<xsl:value-of select="concat(upper-case(substring($name,1,1)),substring($name,2))"/>
</xsl:function>

<!-- templates -->
<xsl:template name="upperFirst">
<xsl:param name="val"/>
Expand Down Expand Up @@ -220,17 +205,5 @@
</xsl:call-template>
</xsl:template>

<xsl:function name="vf:multiplicityAsSymbol">
<xsl:param name="m" as="element()"/>
<xsl:choose>
<xsl:when test="not($m/@minOccurs) and not($m/@maxOccurs)"><!-- do nothing --></xsl:when>
<xsl:when test="number($m/@minOccurs) eq 1 and number($m/@maxOccurs) eq 1"><!-- do nothing --></xsl:when>
<xsl:when test="number($m/@minOccurs) eq 0 and (number($m/@maxOccurs) eq 1 or not($m/@maxOccurs))">0..1</xsl:when>
<xsl:when test="number($m/@minOccurs) eq 0 and $m/@maxOccurs='unbounded'">0..*</xsl:when>
<xsl:when test="(not($m/@minOccurs) or number($m/@minOccurs) eq 1) and $m/@maxOccurs='unbounded'">1..*</xsl:when>
<xsl:when test="not($m/@minOccurs) and $m/@maxOccurs"><xsl:value-of select="concat('1..', $m/@maxOccurs)"/></xsl:when>
<xsl:when test="not($m/@maxOccurs) and $m/@minOccurs"><xsl:value-of select="concat($m/@maxOccurs,'..', $m/@maxOccurs)"/></xsl:when> <!-- this is probably illegal xsd, but just in case -->
<xsl:otherwise><xsl:value-of select="concat($m/@minOccurs,'..', $m/@maxOccurs)"/></xsl:otherwise>
</xsl:choose>
</xsl:function>

</xsl:stylesheet>
57 changes: 57 additions & 0 deletions tools/xslt/common_functions.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="3.0"
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:uml="http://schema.omg.org/spec/UML/2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:vo-dml="http://www.ivoa.net/xml/VODML/v1"
xmlns:vf="http://www.ivoa.net/xml/VODML/functions"

>

<!--
This XSLT script contains common functions that depend only on a single instance of a VO-DML file being in scope.
-->

<!-- this function does not rely on vodml-id being present -->
<xsl:function name="vf:asvodmlref" as="xsd:string">
<xsl:param name="el" as="element()"/>
<xsl:value-of select="concat($el/ancestor::vo-dml:model/name,':',string-join($el/ancestor-or-self::*/name[not(../name() = 'vo-dml:model')], '.'))"/>
</xsl:function>

<xsl:function name="vf:nameFromVodmlref" as="xsd:string">
<xsl:param name="vodml-ref" as="xsd:string"/>
<xsl:value-of select="tokenize($vodml-ref,'[\.:]')[last()]"/>
</xsl:function>

<xsl:function name="vf:upperFirst" as="xsd:string">
<xsl:param name="s" as="xsd:string"/>
<xsl:value-of select="concat(upper-case(substring($s,1,1)),substring($s,2))"/>
</xsl:function>
<xsl:function name="vf:lowerFirst" as="xsd:string">
<xsl:param name="s" as="xsd:string"/>
<xsl:value-of select="concat(lower-case(substring($s,1,1)),substring($s,2))"/>
</xsl:function>

<xsl:function name="vf:capitalize">
<xsl:param name="name"/>
<xsl:value-of select="concat(upper-case(substring($name,1,1)),substring($name,2))"/>
</xsl:function>

<xsl:function name="vf:multiplicityAsSymbol">
<xsl:param name="m" as="element()"/>
<xsl:choose>
<xsl:when test="not($m/@minOccurs) and not($m/@maxOccurs)"><!-- do nothing --></xsl:when>
<xsl:when test="number($m/@minOccurs) eq 1 and number($m/@maxOccurs) eq 1"><!-- do nothing --></xsl:when>
<xsl:when test="number($m/@minOccurs) eq 0 and (number($m/@maxOccurs) eq 1 or not($m/@maxOccurs))">0..1</xsl:when>
<xsl:when test="number($m/@minOccurs) eq 0 and $m/@maxOccurs='unbounded'">0..*</xsl:when>
<xsl:when test="(not($m/@minOccurs) or number($m/@minOccurs) eq 1) and $m/@maxOccurs='unbounded'">1..*</xsl:when>
<xsl:when test="not($m/@minOccurs) and $m/@maxOccurs"><xsl:value-of select="concat('1..', $m/@maxOccurs)"/></xsl:when>
<xsl:when test="not($m/@maxOccurs) and $m/@minOccurs"><xsl:value-of select="concat($m/@maxOccurs,'..', $m/@maxOccurs)"/></xsl:when> <!-- this is probably illegal xsd, but just in case -->
<xsl:otherwise><xsl:value-of select="concat($m/@minOccurs,'..', $m/@maxOccurs)"/></xsl:otherwise>
</xsl:choose>
</xsl:function>

</xsl:stylesheet>
1 change: 1 addition & 0 deletions tools/xslt/vo-dml2gvd.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ intermediate representation to a GraphViz dot file.
extension-element-prefixes="exsl">

<xsl:import href="common.xsl"/>
<xsl:import href="common_functions.xsl"/>

<xsl:output method="text" encoding="UTF-8" indent="no" />

Expand Down

0 comments on commit 90aaffc

Please sign in to comment.