[yelp-tools] yelp-check: Support explicitly allows namespaces in strict validation



commit 41ecb1992c6a632eaa10968639d435542fe4eff9
Author: Shaun McCance <shaunm gnome org>
Date:   Wed Oct 23 23:26:50 2013 -0400

    yelp-check: Support explicitly allows namespaces in strict validation

 tools/yelp-check.in |   12 +++++++++++-
 xslt/mal-rng.xsl    |   21 +++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/tools/yelp-check.in b/tools/yelp-check.in
index 7498012..812bf3a 100755
--- a/tools/yelp-check.in
+++ b/tools/yelp-check.in
@@ -169,6 +169,7 @@ yelp_usage_validate () {
         echo ""
         echo "Options:"
         echo "  --strict            Disallow unknown namespaces"
+        echo "  --allow NS          Explicitly allow namespace NS in strict mode"
     ) 1>&2
 }
 
@@ -619,7 +620,10 @@ 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"` --param rng.strict "$check_strict" 
"$xsl_mal_rng" "$1"
+        xsltproc -o "$check_rng_dir/"`urlencode "$check_rng_file"` \
+            --param rng.strict "$check_strict" \
+            --stringparam rng.strict.allow "$check_strict_allow" \
+            "$xsl_mal_rng" "$1"
     fi
     xmllint --noout --xinclude --noent --relaxng "$check_rng_dir/$check_rng_file" "$1" > "$check_out_file" 
2>&1
     ret="$?"
@@ -635,12 +639,18 @@ yelp_validate () {
     fi
     gret="0"
     check_strict="false()"
+    check_strict_allow=""
     while [ "$#" != "0" ]; do
         case "$1" in
             "--strict")
                 check_strict="true()"
                 shift
                 ;;
+            "--allow")
+                shift
+                check_strict_allow="$check_strict_allow $1"
+                shift
+                ;;
             *)
                 break
                 ;;
diff --git a/xslt/mal-rng.xsl b/xslt/mal-rng.xsl
index aebda73..d6d8895 100644
--- a/xslt/mal-rng.xsl
+++ b/xslt/mal-rng.xsl
@@ -10,6 +10,7 @@
     version="1.0">
 
 <xsl:param name="rng.strict" select="false()"/>
+<xsl:param name="rng.strict.allow" select="''"/>
 
 <xsl:template match="/*">
   <xsl:variable name="version">
@@ -89,6 +90,26 @@
   <xsl:choose>
     <xsl:when test="$rng.strict and rng:anyName">
       <xsl:choose>
+        <xsl:when test="$rng.strict.allow != ''">
+          <xsl:copy>
+            <choice>
+              <xsl:if test="self::rng:attribute/ancestor::rng:element[1]/rng:anyName">
+                <nsName ns=""/>
+              </xsl:if>
+              <xsl:for-each select="str:split($rng.strict.allow)">
+                <nsName ns="{.}"/>
+              </xsl:for-each>
+              <xsl:if test="ancestor::rng:define/@name = 'mal_attr_external'">
+                <nsName ns="http://www.w3.org/XML/1998/namespace"/>
+              </xsl:if>
+            </choice>
+            <xsl:apply-templates mode="rng.mode" select="rng:anyName/following-sibling::*">
+              <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:when>
         <xsl:when test="ancestor::rng:define/@name = 'mal_attr_external'">
           <xsl:copy>
             <nsName ns="http://www.w3.org/XML/1998/namespace"/>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]