Skip to content

Commit

Permalink
Merge pull request #329 from cellar-wg/clean-schema
Browse files Browse the repository at this point in the history
Clean schema
  • Loading branch information
dericed authored Jul 22, 2019
2 parents f480ed4 + 65a11d5 commit 2d56b71
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ OUTPUT_TAGS := $(STATUS_TAGS)ietf-cellar-tags-$(VERSION_TAGS)

all: $(OUTPUT_MATROSKA).html $(OUTPUT_MATROSKA).txt $(OUTPUT_MATROSKA).xml $(OUTPUT_CODEC).html $(OUTPUT_CODEC).txt $(OUTPUT_CODEC).xml $(OUTPUT_TAGS).html $(OUTPUT_TAGS).txt $(OUTPUT_TAGS).xml

ebml_matroska_elements4rfc.md: ebml_matroska.xml transforms/ebml_schema2markdown4rfc.xsl
xsltproc transforms/ebml_schema2markdown4rfc.xsl ebml_matroska.xml > $@
matroska_xsd.xml: transforms/schema_clean.xsl ebml_matroska.xml
xsltproc transforms/schema_clean.xsl ebml_matroska.xml > $@

check: matroska_xsd.xml
xmllint --noout --schema ../ebml-specification/EBMLSchema.xsd matroska_xsd.xml

ebml_matroska_elements4rfc.md: transforms/ebml_schema2markdown4rfc.xsl matroska_xsd.xml
xsltproc transforms/ebml_schema2markdown4rfc.xsl matroska_xsd.xml > $@

$(OUTPUT_MATROSKA).md: index_matroska.md diagram.md matroska_schema_section_header.md ebml_matroska_elements4rfc.md ordering.md chapters.md attachments.md cues.md streaming.md menu.md notes.md
cat $^ | grep -v '^---' > $@
Expand Down
124 changes: 124 additions & 0 deletions transforms/schema_clean.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:str="http://exslt.org/strings" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="str xhtml ebml"
xmlns="https://ietf.org/cellar/ebml" xmlns:ebml="https://ietf.org/cellar/ebml">
<!-- TODO: make purpose mandatory or default to "definition" -->
<xsl:output encoding="utf-8" method="xml" version="1.0" indent="yes" />
<xsl:template match="ebml:EBMLSchema">
<EBMLSchema>
<xsl:attribute name="docType"><xsl:value-of select="@docType" /></xsl:attribute>
<xsl:attribute name="version"><xsl:value-of select="@version" /></xsl:attribute>
<xsl:apply-templates select="ebml:element|comment()"/>
</EBMLSchema>
</xsl:template>

<xsl:template match="ebml:element">
<element>
<xsl:attribute name="name">placeholder before parsePath is called</xsl:attribute>
<xsl:attribute name="path"><xsl:value-of select="@path" /></xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="type"><xsl:value-of select="@type" /></xsl:attribute>
<xsl:if test="@minver and @minver!='1'">
<xsl:attribute name="minver"><xsl:value-of select="@minver" /></xsl:attribute>
</xsl:if>
<xsl:if test="@maxver">
<xsl:attribute name="maxver"><xsl:value-of select="@maxver" /></xsl:attribute>
</xsl:if>
<xsl:if test="@range">
<xsl:attribute name="range"><xsl:value-of select="@range" /></xsl:attribute>
</xsl:if>
<xsl:if test="@length">
<xsl:attribute name="length"><xsl:value-of select="@length" /></xsl:attribute>
</xsl:if>
<xsl:if test="@default">
<xsl:attribute name="default"><xsl:value-of select="@default" /></xsl:attribute>
</xsl:if>
<xsl:call-template name="parsePath">
<xsl:with-param name="Path"><xsl:value-of select="@path" /></xsl:with-param>
</xsl:call-template>
<xsl:if test="@recurring">
<xsl:attribute name="recurring"><xsl:value-of select="@recurring" /></xsl:attribute>
</xsl:if>
<xsl:if test="@unknownsizeallowed">
<xsl:attribute name="unknownsizeallowed"><xsl:value-of select="@unknownsizeallowed" /></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="ebml:documentation"/>
<xsl:if test="ebml:restriction">
<restriction>
<xsl:for-each select="ebml:restriction/ebml:enum">
<xsl:sort select="ebml:value"/>
<enum value="{@value}">
<xsl:if test="@label">
<xsl:attribute name="label"><xsl:value-of select="@label" /></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="ebml:documentation"/>
</enum>
</xsl:for-each>
</restriction>
</xsl:if>
</element>
</xsl:template>
<xsl:template match="ebml:documentation">
<documentation>
<xsl:attribute name="lang"><xsl:value-of select="@lang" /></xsl:attribute>
<xsl:attribute name="purpose">
<xsl:choose>
<xsl:when test="@purpose">
<xsl:value-of select="@purpose"/>
</xsl:when>
<xsl:otherwise>definition</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<!-- make sure the links are kept -->
<xsl:apply-templates/>
</documentation>
</xsl:template>

<!-- HTML tags found in documentation -->
<xsl:template match="ebml:a">
<a href="{@href}"><xsl:apply-templates/></a>
</xsl:template>
<xsl:template match="ebml:br">
<br/><xsl:apply-templates/>
</xsl:template>
<xsl:template match="ebml:strong">
<strong><xsl:apply-templates/></strong>
</xsl:template>

<xsl:template match="comment()">
<xsl:comment>
<xsl:value-of select="."/>
</xsl:comment>
</xsl:template>

<xsl:template name="parsePath">
<xsl:param name="Path"/>
<xsl:variable name="EBMLElementOccurrence" select="substring-before($Path,'(')"/>
<xsl:variable name="EBMLMinOccurrence" select="substring-before($EBMLElementOccurrence,'*')"/>
<xsl:variable name="EBMLMaxOccurrence" select="substring-after($EBMLElementOccurrence,'*')"/>
<xsl:variable name="EBMLMasterPath" select="substring-before(substring-after($Path,'('),')')"/>
<xsl:call-template name="get-element-name">
<xsl:with-param name="value"><xsl:value-of select="$EBMLMasterPath" /></xsl:with-param>
</xsl:call-template>
<xsl:if test="$EBMLMinOccurrence and $EBMLMinOccurrence!='0'">
<xsl:attribute name="minOccurs"><xsl:value-of select="$EBMLMinOccurrence" /></xsl:attribute>
</xsl:if>
<xsl:if test="$EBMLMaxOccurrence">
<xsl:attribute name="maxOccurs"><xsl:value-of select="$EBMLMaxOccurrence" /></xsl:attribute>
</xsl:if>
</xsl:template>

<xsl:template name="get-element-name">
<xsl:param name="value"/>
<xsl:param name="separator"/>
<xsl:choose>
<xsl:when test="contains($value, '\')">
<xsl:call-template name="get-element-name">
<xsl:with-param name="value"><xsl:value-of select="substring-after($value, '\')" /></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="name"><xsl:value-of select="$value" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 2d56b71

Please sign in to comment.