summaryrefslogtreecommitdiff
path: root/xslt
diff options
context:
space:
mode:
authorShaun McCance <shaunm@gnome.org>2011-05-05 12:03:20 -0400
committerShaun McCance <shaunm@gnome.org>2011-05-05 12:03:20 -0400
commit2807cedae09c2540194a7ded6a2726199e2ecaca (patch)
tree04bc102d2f5ddbc1429816198f845f8b4e809a7d /xslt
parent17a7985b7c05a82e379caac319cef7a9f298f180 (diff)
downloadyelp-tools-2807cedae09c2540194a7ded6a2726199e2ecaca.tar.gz
yelp-check: Adding validate subcommand for Mallard
Diffstat (limited to 'xslt')
-rw-r--r--xslt/Makefile.am6
-rw-r--r--xslt/mal-rng.xsl94
2 files changed, 100 insertions, 0 deletions
diff --git a/xslt/Makefile.am b/xslt/Makefile.am
new file mode 100644
index 0000000..31384d7
--- /dev/null
+++ b/xslt/Makefile.am
@@ -0,0 +1,6 @@
+xsldir=$(datadir)/yelp-tools/xslt
+
+xsl_DATA = \
+ mal-rng.xsl
+
+EXTRA_DIST=$(xsl_DATA)
diff --git a/xslt/mal-rng.xsl b/xslt/mal-rng.xsl
new file mode 100644
index 0000000..9f80c65
--- /dev/null
+++ b/xslt/mal-rng.xsl
@@ -0,0 +1,94 @@
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:str="http://exslt.org/strings"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:mal="http://projectmallard.org/1.0/"
+ xmlns:rng="http://relaxng.org/ns/structure/1.0"
+ xmlns="http://relaxng.org/ns/structure/1.0"
+ exclude-result-prefixes="str exsl"
+ version="1.0">
+
+<xsl:template match="/*">
+ <xsl:variable name="version">
+ <xsl:choose>
+ <xsl:when test="string(@version) != ''">
+ <xsl:value-of select="@version"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="'1.0'"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:variable name="uris">
+ <xsl:for-each select="str:split($version)">
+ <xsl:choose>
+ <xsl:when test="contains(., ':')">
+ <xsl:value-of select="."/>
+ </xsl:when>
+ <xsl:when test="contains(., '/')">
+ <xsl:variable name="ext" select="substring-before(., '/')"/>
+ <xsl:variable name="ver" select="substring-after(., '/')"/>
+ <xsl:text>http://projectmallard.org/</xsl:text>
+ <xsl:value-of select="concat($ext, '/', $ver, '/', $ext, '-', $ver, '.rng')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>http://projectmallard.org/</xsl:text>
+ <xsl:value-of select="concat(., '/mallard-', ., '.rng')"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> </xsl:text>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:variable name="nss_">
+ <xsl:for-each select="str:split($uris)">
+ <xsl:for-each select="document(.)/*">
+ <nsName ns="{@ns}"/>
+ </xsl:for-each>
+ </xsl:for-each>
+ <nsName ns=""/>
+ </xsl:variable>
+ <xsl:variable name="nss" select="exsl:node-set($nss_)/*"/>
+ <grammar>
+ <xsl:for-each select="str:split($uris)">
+ <xsl:for-each select="document(.)/rng:grammar">
+ <xsl:apply-templates mode="rng.mode" select="*">
+ <xsl:with-param name="ns" select="string(@ns)"/>
+ <xsl:with-param name="nss" select="$nss"/>
+ </xsl:apply-templates>
+ </xsl:for-each>
+ </xsl:for-each>
+ </grammar>
+</xsl:template>
+
+<xsl:template mode="rng.mode" match="text()">
+ <xsl:value-of select="."/>
+</xsl:template>
+
+<xsl:template mode="rng.mode" match="*">
+ <xsl:param name="ns"/>
+ <xsl:param name="nss"/>
+ <xsl:copy>
+ <xsl:for-each select="@*">
+ <xsl:copy-of select="."/>
+ </xsl:for-each>
+ <xsl:if test="self::rng:element and not(@ns)">
+ <xsl:attribute name="ns">
+ <xsl:value-of select="$ns"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates mode="rng.mode">
+ <xsl:with-param name="ns" select="$ns"/>
+ <xsl:with-param name="nss" select="$nss"/>
+ </xsl:apply-templates>
+ </xsl:copy>
+</xsl:template>
+
+<xsl:template mode="rng.mode" match="rng:anyName/rng:except">
+ <xsl:param name="ns"/>
+ <xsl:param name="nss"/>
+ <except>
+ <xsl:copy-of select="$nss"/>
+ </except>
+</xsl:template>
+
+</xsl:stylesheet>