summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@gnome.org>2012-03-06 13:53:57 -0500
committerShaun McCance <shaunm@gnome.org>2012-03-06 13:53:57 -0500
commit81b0d47527816b0d9d4e2908aca7616878e98cad (patch)
tree23b5b43fc1efdad98088b01b71eed53c19e1e9e7
parent591350f373281cb818d97de6d64bf51feae380bd (diff)
downloadyelp-tools-81b0d47527816b0d9d4e2908aca7616878e98cad.tar.gz
yelp-check: Adding --strict option to validate
-rwxr-xr-xtools/yelp-check.in17
-rw-r--r--xslt/mal-rng.xsl79
2 files changed, 60 insertions, 36 deletions
diff --git a/tools/yelp-check.in b/tools/yelp-check.in
index b6906df..ee35d55 100755
--- a/tools/yelp-check.in
+++ b/tools/yelp-check.in
@@ -123,6 +123,9 @@ yelp_usage_validate () {
echo " Validate FILES against the appropriate DTD or RNG."
echo " For Mallard pages, perform automatic RNG merging"
echo " based on the version attribute."
+ echo ""
+ echo "Options:"
+ echo " --strict Disallow unknown namespaces"
) 1>&2
}
@@ -460,7 +463,7 @@ yelp_validate_page () {
# version strings often contain slashes. But xsltproc treats the
# -o option as a URL and urldecodes, so doubly urlencode, because
# we want the urlencoded string to be the on-disk name.
- xsltproc -o "$check_rng_dir/"`urlencode "$check_rng_file"` "$xsl_mal_rng" "$1"
+ xsltproc -o "$check_rng_dir/"`urlencode "$check_rng_file"` --param rng.strict "$check_strict" "$xsl_mal_rng" "$1"
fi
xmllint --noout --xinclude --noent --relaxng "$check_rng_dir/$check_rng_file" "$1" > "$check_out_file" 2>&1
ret="$?"
@@ -475,6 +478,18 @@ yelp_validate () {
exit 1
fi
gret="0"
+ check_strict="false()"
+ while [ "$#" != "0" ]; do
+ case "$1" in
+ "--strict")
+ check_strict="true()"
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
for xml in "$@"; do
ext=`echo "$1" | sed -e 's/.*\.//'`
if [ -d "$xml" ]; then
diff --git a/xslt/mal-rng.xsl b/xslt/mal-rng.xsl
index e80e44c..6049dcd 100644
--- a/xslt/mal-rng.xsl
+++ b/xslt/mal-rng.xsl
@@ -8,6 +8,8 @@
exclude-result-prefixes="mal str exsl rng"
version="1.0">
+<xsl:param name="rng.strict" select="false()"/>
+
<xsl:template match="/*">
<xsl:variable name="version">
<xsl:choose>
@@ -80,41 +82,48 @@
<xsl:param name="first"/>
<xsl:param name="ns"/>
<xsl:param name="nss"/>
- <xsl:variable name="nsmunge" select="self::rng:element or self::rng:attribute"/>
- <xsl:copy>
- <xsl:for-each select="@*">
- <xsl:choose>
- <xsl:when test="$nsmunge and local-name(.) = 'name' and contains(., ':')">
- <xsl:attribute name="name">
- <xsl:value-of select="substring-after(., ':')"/>
- </xsl:attribute>
- </xsl:when>
- <xsl:otherwise>
- <xsl:copy-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <xsl:if test="$nsmunge and not(@ns)">
- <xsl:choose>
- <xsl:when test="contains(@name, ':')">
- <xsl:variable name="prefix" select="substring-before(@name, ':')"/>
- <xsl:attribute name="ns">
- <xsl:value-of select="namespace::*[local-name(.) = $prefix]"/>
- </xsl:attribute>
- </xsl:when>
- <xsl:when test="self::rng:element">
- <xsl:attribute name="ns">
- <xsl:value-of select="$ns"/>
- </xsl:attribute>
- </xsl:when>
- </xsl:choose>
- </xsl:if>
- <xsl:apply-templates mode="rng.mode">
- <xsl:with-param name="first" select="$first"/>
- <xsl:with-param name="ns" select="$ns"/>
- <xsl:with-param name="nss" select="$nss"/>
- </xsl:apply-templates>
- </xsl:copy>
+ <xsl:choose>
+ <xsl:when test="$rng.strict and rng:anyName">
+ <empty/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="nsmunge" select="self::rng:element or self::rng:attribute"/>
+ <xsl:copy>
+ <xsl:for-each select="@*">
+ <xsl:choose>
+ <xsl:when test="$nsmunge and local-name(.) = 'name' and contains(., ':')">
+ <xsl:attribute name="name">
+ <xsl:value-of select="substring-after(., ':')"/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:if test="$nsmunge and not(@ns)">
+ <xsl:choose>
+ <xsl:when test="contains(@name, ':')">
+ <xsl:variable name="prefix" select="substring-before(@name, ':')"/>
+ <xsl:attribute name="ns">
+ <xsl:value-of select="namespace::*[local-name(.) = $prefix]"/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:when test="self::rng:element">
+ <xsl:attribute name="ns">
+ <xsl:value-of select="$ns"/>
+ </xsl:attribute>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:if>
+ <xsl:apply-templates mode="rng.mode">
+ <xsl:with-param name="first" select="$first"/>
+ <xsl:with-param name="ns" select="$ns"/>
+ <xsl:with-param name="nss" select="$nss"/>
+ </xsl:apply-templates>
+ </xsl:copy>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<xsl:template mode="rng.mode" match="rng:start">