diff options
| author | Stefan Behnel <stefan_ml@behnel.de> | 2018-11-23 22:09:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-23 22:09:30 +0100 |
| commit | 6ce2892aa33a329ff89abdf582ecae02cf55105b (patch) | |
| tree | 3321d7f106d53521aff2da219233ec868670a1bc /src | |
| parent | 51308a28ac6e4e5ec7e014932a1ef39c1f99c5de (diff) | |
| parent | e08620788d739d98a869e068a0f79af04ea4ef48 (diff) | |
| download | python-lxml-6ce2892aa33a329ff89abdf582ecae02cf55105b.tar.gz | |
Merge branch 'master' into master
Diffstat (limited to 'src')
| -rw-r--r-- | src/lxml/isoschematron/__init__.py | 4 | ||||
| -rw-r--r-- | src/lxml/isoschematron/resources/rng/iso-schematron.rng | 107 | ||||
| -rw-r--r-- | src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl | 83 | ||||
| -rw-r--r-- | src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt | 167 | ||||
| -rw-r--r-- | src/lxml/xpath.pxi | 2 |
5 files changed, 234 insertions, 129 deletions
diff --git a/src/lxml/isoschematron/__init__.py b/src/lxml/isoschematron/__init__.py index e66f6a10..5967b109 100644 --- a/src/lxml/isoschematron/__init__.py +++ b/src/lxml/isoschematron/__init__.py @@ -63,8 +63,8 @@ svrl_validation_errors = _etree.XPath( # RelaxNG validator for schematron schemas -schematron_schema_valid = _etree.RelaxNG(_etree.parse( - os.path.join(_resources_dir, 'rng', 'iso-schematron.rng'))) +schematron_schema_valid = _etree.RelaxNG( + file=os.path.join(_resources_dir, 'rng', 'iso-schematron.rng')) def stylesheet_params(**kwargs): diff --git a/src/lxml/isoschematron/resources/rng/iso-schematron.rng b/src/lxml/isoschematron/resources/rng/iso-schematron.rng index d822f0d6..a4f504af 100644 --- a/src/lxml/isoschematron/resources/rng/iso-schematron.rng +++ b/src/lxml/isoschematron/resources/rng/iso-schematron.rng @@ -1,9 +1,29 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright © ISO/IEC 2015 --> <!-- - (c) International Organization for Standardization 2005. - Permission to copy in any form is granted for use with conforming - SGML systems and applications as defined in ISO 8879, - provided this notice is included in all copies. + The following permission notice and disclaimer shall be included in all + copies of this XML schema ("the Schema"), and derivations of the Schema: + + Permission is hereby granted, free of charge in perpetuity, to any + person obtaining a copy of the Schema, to use, copy, modify, merge and + distribute free of charge, copies of the Schema for the purposes of + developing, implementing, installing and using software based on the + Schema, and to permit persons to whom the Schema is furnished to do so, + subject to the following conditions: + + THE SCHEMA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SCHEMA OR THE USE OR + OTHER DEALINGS IN THE SCHEMA. + + In addition, any modified copy of the Schema shall include the following + notice: + + "THIS SCHEMA HAS BEEN MODIFIED FROM THE SCHEMA DEFINED IN ISO/IEC 19757-3, + AND SHOULD NOT BE INTERPRETED AS COMPLYING WITH THAT STANDARD". --> <grammar ns="http://purl.oclc.org/dsdl/schematron" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> @@ -63,6 +83,10 @@ <optional> <ref name="diagnostics"/> </optional> + <optional> + <!-- edited (lxml): required in standard, optional here (since it can be empty anyway) --> + <ref name="properties"/> + </optional> </group> </interleave> </element> @@ -105,6 +129,11 @@ <data type="IDREFS"/> </attribute> </optional> + <optional> + <attribute name="properties"> + <data type="IDREFS"/> + </attribute> + </optional> <ref name="rich"/> <ref name="linkable"/> <interleave> @@ -178,9 +207,14 @@ </define> <define name="extends"> <element name="extends"> - <attribute name="rule"> - <data type="IDREF"/> - </attribute> + <choice> + <attribute name="rule"> + <data type="IDREF"/> + </attribute> + <attribute name="href"> + <ref name="uriValue"/> + </attribute> + </choice> <ref name="foreign-empty"/> </element> </define> @@ -189,9 +223,14 @@ <attribute name="name"> <ref name="nameValue"/> </attribute> - <attribute name="value"> - <data type="string" datatypeLibrary=""/> - </attribute> + <choice> + <attribute name="value"> + <data type="string" datatypeLibrary=""/> + </attribute> + <oneOrMore> + <ref name="foreign-element"/> + </oneOrMore> + </choice> </element> </define> <define name="name"> @@ -257,6 +296,11 @@ </define> <define name="pattern"> <element name="pattern"> + <optional> + <attribute name="documents"> + <ref name="pathValue"/> + </attribute> + </optional> <ref name="rich"/> <interleave> <ref name="foreign"/> @@ -367,6 +411,41 @@ </interleave> </element> </define> + <define name="properties"> + <element name="properties"> + <zeroOrMore> + <ref name="property"/> + </zeroOrMore> + </element> + </define> + <define name="property"> + <element name="property"> + <attribute name="id"> + <data type="ID"/> + </attribute> + <optional> + <attribute name="role"> + <ref name="roleValue"/> + </attribute> + </optional> + <optional> + <attribute name="scheme"/> + </optional> + <interleave> + <ref name="foreign"/> + <zeroOrMore> + <choice> + <text/> + <ref name="name"/> + <ref name="value-of"/> + <ref name="emph"/> + <ref name="dir"/> + <ref name="span"/> + </choice> + </zeroOrMore> + </interleave> + </element> + </define> <define name="report"> <element name="report"> <attribute name="test"> @@ -387,6 +466,11 @@ <data type="IDREFS"/> </attribute> </optional> + <optional> + <attribute name="properties"> + <data type="IDREFS"/> + </attribute> + </optional> <ref name="rich"/> <ref name="linkable"/> <interleave> @@ -434,6 +518,7 @@ <ref name="assert"/> <ref name="report"/> <ref name="extends"/> + <ref name="p"/> </choice> </oneOrMore> </group> @@ -459,6 +544,7 @@ <ref name="assert"/> <ref name="report"/> <ref name="extends"/> + <ref name="p"/> </choice> </oneOrMore> </group> @@ -501,6 +587,7 @@ <attribute name="href"> <ref name="uriValue"/> </attribute> + <ref name="foreign-empty"/> </element> </define> <define name="rich"> diff --git a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl index 057c7c1f..50183952 100644 --- a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl +++ b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl @@ -6,10 +6,11 @@ This is a preprocessor for ISO Schematron, which implements abstract patterns. It also * extracts a particular schema using an ID, where there are multiple - schemas, such as when they are embedded in the same NVDL script - * experimentally, allows parameter recognition and substitution inside - text as well as @context, @test, & @select. - + schemas, such as when they are embedded in the same NVDL script + * allows parameter substitution inside @context, @test, @select, @path + * experimentally, allows parameter recognition and substitution inside + text (NOTE: to be removed, for compataibility with other implementations, + please do not use this) This should be used after iso-dsdl-include.xsl and before the skeleton or meta-stylesheet (e.g. iso-svrl.xsl) . It only requires XSLT 1. @@ -17,8 +18,45 @@ Each kind of inclusion can be turned off (or on) on the command line. --> -<!-- - VERSION INFORMATION + +<!-- +Open Source Initiative OSI - The MIT License:Licensing +[OSI Approved License] + +This source code was previously available under the zlib/libpng license. +Attribution is polite. + +The MIT License + +Copyright (c) 2004-2010 Rick Jellife and Academia Sinica Computing Centre, Taiwan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +--> + +<!-- +VERSION INFORMATION + 2013-09-19 RJ + * Allow macro expansion in @path attributes, eg. for sch:name/@path + + 2010-07-10 RJ + * Move to MIT license + 2008-09-18 RJ * move out param test from iso:schema template to work with XSLT 1. (Noah Fontes) @@ -40,35 +78,11 @@ * Original written for old namespace * http://www.topologi.com/resources/iso-pre-pro.xsl --> -<!-- - LEGAL INFORMATION - - Copyright (c) 2000-2008 Rick Jelliffe and Academia Sinica Computing Center, Taiwan - - This software is provided 'as-is', without any express or implied warranty. - In no event will the authors be held liable for any damages arising from - the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it freely, - subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not claim - that you wrote the original software. If you use this software in a product, - an acknowledgment in the product documentation would be appreciated but is - not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. ---> <xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:iso="http://purl.oclc.org/dsdl/schematron" xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl" - xmlns:iae="http://www.schematron.com/namespace/iae" > @@ -231,7 +245,7 @@ <xslt:template mode="iae:do-pattern" match="*"> <xslt:param name="caller"/> <xslt:copy> - <xslt:for-each select="@*[name()='test' or name()='context' or name()='select']"> + <xslt:for-each select="@*[name()='test' or name()='context' or name()='select' or name()='path' ]"> <xslt:attribute name="{name()}"> <xslt:call-template name="iae:macro-expand"> <xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param> @@ -239,12 +253,13 @@ </xslt:call-template> </xslt:attribute> </xslt:for-each> - <xslt:copy-of select="@*[name()!='test'][name()!='context'][name()!='select']" /> + <xslt:copy-of select="@*[name()!='test'][name()!='context'][name()!='select'][name()!='path']" /> <xsl:for-each select="node()"> <xsl:choose> <!-- Experiment: replace macros in text as well, to allow parameterized assertions and so on, without having to have spurious <iso:value-of> calls and multiple - delimiting --> + delimiting. + NOTE: THIS FUNCTIONALITY WILL BE REMOVED IN THE FUTURE --> <xsl:when test="self::text()"> <xslt:call-template name="iae:macro-expand"> <xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param> @@ -293,4 +308,6 @@ </xsl:choose> </xslt:template> + + </xslt:stylesheet>
\ No newline at end of file diff --git a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt index d9f68c5a..e5d6dfcd 100644 --- a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt +++ b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt @@ -1,83 +1,84 @@ -ISO SCHEMATRON 2009 - -XSLT implementation by Rick Jelliffe with assistance from members of Schematron-love-in maillist. - -2009-03-18 - -Two distributions are available. One is for XSLT1 engines. -The other is for XSLT2 engines, such as SAXON 9. - - -This version of Schematron splits the process into a pipeline of several different XSLT stages. - -1) First, preprocess your Schematron schema with iso_dsdl_include.xsl. -This is a macro processor to assemble the schema from various parts. -If your schema is not in separate parts, you can skip this stage. - -2) Second, preprocess the output from stage 1 with iso_abstract_expand.xsl. -This is a macro processor to convert abstract patterns to real patterns. -If your schema does not use abstract patterns, you can skip this -stage. - -3) Third, compile the Schematron schema into an XSLT script. -This will typically use iso_svrl_for_xslt1.xsl or iso_svrl_for_xslt2.xsl -(which in turn invoke iso_schematron_skeleton_for_xslt1.xsl or iso_schematron_skeleton_for_saxon.xsl) -However, other "meta-styleseets" are also in common use; the principle of operation is the same. -If your schema uses Schematron phases, supply these as command line/invocation parameters -to this process. - -4) Fourth, run the script generated by stage 3 against the document being validated. -If you are using the SVRL script, then the output of validation will be an XML document. -If your schema uses Schematron parameters, supply these as command line/invocation parameters -to this process. - - -The XSLT2 distribution also features several next generation features, -such as validating multiple documents. See the source code for details. - -Schematron assertions can be written in any language, of course; the file -sch-messages-en.xhtml contains the diagnostics messages from the XSLT2 skeleton -in English, and this can be used as template to localize the skeleton's -error messages. Note that typically programming errors in Schematron are XPath -errors, which requires localized messages from the XSLT engine. - -ANT ---- -To give an example of how to process a document, here is a sample ANT task. - -<target name="schematron-compile-test" > - - <!-- expand inclusions --> - <xslt basedir="test/schematron" - style="iso_dsdl_include.xsl" in="test.sch" out="test1.sch"> - <classpath> - <pathelement location="${lib.dir}/saxon9.jar"/> - </classpath> - </xslt> - - <!-- expand abstract patterns --> - <xslt basedir="test/schematron" - style="iso_abstract_expand.xsl" in="test1.sch" out="test2.sch"> - <classpath> - <pathelement location="${lib.dir}/saxon9.jar"/> - </classpath> - </xslt> - - - - <!-- compile it --> - <xslt basedir="test/schematron" - style="iso_svrl_for_xslt2.xsl" in="test2.sch" out="test.xsl"> - <classpath> - <pathelement location="${lib.dir}/saxon9.jar"/> - </classpath> - </xslt> - - <!-- validate --> - <xslt basedir="test/schematron" - style="test.xsl" in="instance.xml" out="instance.svrlt"> - <classpath> - <pathelement location="${lib.dir}/saxon9.jar"/> - </classpath> - </xslt> - </target>
\ No newline at end of file +ISO SCHEMATRON 2010
+
+XSLT implementation by Rick Jelliffe with assistance from members of Schematron-love-in maillist.
+
+2010-04-21
+
+Two distributions are available. One is for XSLT1 engines.
+The other is for XSLT2 engines, such as SAXON 9.
+
+
+This version of Schematron splits the process into a pipeline of several different XSLT stages.
+
+1) First, preprocess your Schematron schema with iso_dsdl_include.xsl.
+This is a macro processor to assemble the schema from various parts.
+If your schema is not in separate parts, you can skip this stage.
+This stage also generates error messages for some common XPath syntax problems.
+
+2) Second, preprocess the output from stage 1 with iso_abstract_expand.xsl.
+This is a macro processor to convert abstract patterns to real patterns.
+If your schema does not use abstract patterns, you can skip this
+stage.
+
+3) Third, compile the Schematron schema into an XSLT script.
+This will typically use iso_svrl_for_xslt1.xsl or iso_svrl_for_xslt2.xsl
+(which in turn invoke iso_schematron_skeleton_for_xslt1.xsl or iso_schematron_skeleton_for_saxon.xsl)
+However, other "meta-stylesheets" are also in common use; the principle of operation is the same.
+If your schema uses Schematron phases, supply these as command line/invocation parameters
+to this process.
+
+4) Fourth, run the script generated by stage 3 against the document being validated.
+If you are using the SVRL script, then the output of validation will be an XML document.
+If your schema uses Schematron parameters, supply these as command line/invocation parameters
+to this process.
+
+
+The XSLT2 distribution also features several next generation features,
+such as validating multiple documents. See the source code for details.
+
+Schematron assertions can be written in any language, of course; the file
+sch-messages-en.xhtml contains the diagnostics messages from the XSLT2 skeleton
+in English, and this can be used as template to localize the skeleton's
+error messages. Note that typically programming errors in Schematron are XPath
+errors, which requires localized messages from the XSLT engine.
+
+ANT
+---
+To give an example of how to process a document, here is a sample ANT task.
+
+<target name="schematron-compile-test" >
+
+ <!-- expand inclusions -->
+ <xslt basedir="test/schematron"
+ style="iso_dsdl_include.xsl" in="test.sch" out="test1.sch">
+ <classpath>
+ <pathelement location="${lib.dir}/saxon9.jar"/>
+ </classpath>
+ </xslt>
+
+ <!-- expand abstract patterns -->
+ <xslt basedir="test/schematron"
+ style="iso_abstract_expand.xsl" in="test1.sch" out="test2.sch">
+ <classpath>
+ <pathelement location="${lib.dir}/saxon9.jar"/>
+ </classpath>
+ </xslt>
+
+
+
+ <!-- compile it -->
+ <xslt basedir="test/schematron"
+ style="iso_svrl_for_xslt2.xsl" in="test2.sch" out="test.xsl">
+ <classpath>
+ <pathelement location="${lib.dir}/saxon9.jar"/>
+ </classpath>
+ </xslt>
+
+ <!-- validate -->
+ <xslt basedir="test/schematron"
+ style="test.xsl" in="instance.xml" out="instance.svrlt">
+ <classpath>
+ <pathelement location="${lib.dir}/saxon9.jar"/>
+ </classpath>
+ </xslt>
+ </target>
diff --git a/src/lxml/xpath.pxi b/src/lxml/xpath.pxi index 6c446737..784987d4 100644 --- a/src/lxml/xpath.pxi +++ b/src/lxml/xpath.pxi @@ -101,7 +101,7 @@ cdef class _XPathContext(_BaseContext): cdef void _registerExsltFunctionsForNamespaces( - void* _c_href, void* _ctxt, xmlChar* c_prefix): + void* _c_href, void* _ctxt, const_xmlChar* c_prefix): c_href = <const_xmlChar*> _c_href ctxt = <xpath.xmlXPathContext*> _ctxt |
