diff --git a/include/XSLT/impl/handler/xslt_apply_imports_handler.hpp b/include/XSLT/impl/handler/xslt_apply_imports_handler.hpp index 155cc2d9..3c31e268 100644 --- a/include/XSLT/impl/handler/xslt_apply_imports_handler.hpp +++ b/include/XSLT/impl/handler/xslt_apply_imports_handler.hpp @@ -47,9 +47,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:apply-imports element must be empty"); + verifyNoCharacterData(ch, "xsl:apply-imports"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp b/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp index 5a7bfb63..a7b94536 100644 --- a/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp +++ b/include/XSLT/impl/handler/xslt_apply_templates_handler.hpp @@ -83,9 +83,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:apply-templates element can only contain xsl:sort and xsl:with-param elements."); + verifyNoCharacterData(ch, "xsl:apply-templates"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_call_template_handler.hpp b/include/XSLT/impl/handler/xslt_call_template_handler.hpp index 0fb68b66..eae6e039 100644 --- a/include/XSLT/impl/handler/xslt_call_template_handler.hpp +++ b/include/XSLT/impl/handler/xslt_call_template_handler.hpp @@ -47,7 +47,7 @@ public: return; } // if(localName == "with-param") - throw SAX::SAXException("xsl:apply-templates can only contain xsl:sort and xsl:with-param elements."); + throw SAX::SAXException("xsl:call-template can only contain xsl:sort and xsl:with-param elements."); } // startElement virtual void endElement(const std::string& /* namespaceURI */, diff --git a/include/XSLT/impl/handler/xslt_choose_handler.hpp b/include/XSLT/impl/handler/xslt_choose_handler.hpp index b09e76da..33e47a2b 100644 --- a/include/XSLT/impl/handler/xslt_choose_handler.hpp +++ b/include/XSLT/impl/handler/xslt_choose_handler.hpp @@ -146,9 +146,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:choose element may not contain text. Only xsl:when and xsl:otherwise are allowed"); + verifyNoCharacterData(ch, "xsl:choose"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_copy_handler.hpp b/include/XSLT/impl/handler/xslt_copy_handler.hpp index 92df2846..aae3ed93 100644 --- a/include/XSLT/impl/handler/xslt_copy_handler.hpp +++ b/include/XSLT/impl/handler/xslt_copy_handler.hpp @@ -67,9 +67,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:copy-of element must be empty"); + verifyNoCharacterData(ch, "xsl:copy-of"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_include_handler.hpp b/include/XSLT/impl/handler/xslt_include_handler.hpp index 023f302b..75360def 100644 --- a/include/XSLT/impl/handler/xslt_include_handler.hpp +++ b/include/XSLT/impl/handler/xslt_include_handler.hpp @@ -4,7 +4,6 @@ #include #include "xslt_constants.hpp" -#include "xslt_value_validation.hpp" namespace Arabica { @@ -104,7 +103,7 @@ public: virtual void characters(const std::string& ch) { if(no_content_) - throw SAX::SAXException("xsl:include/xsl:import must be empty"); + verifyNoCharacterData(ch, "xsl:include/xsl:import"); context_->parentHandler().characters(ch); } // characters diff --git a/include/XSLT/impl/handler/xslt_item_container_handler.hpp b/include/XSLT/impl/handler/xslt_item_container_handler.hpp index 515f2cd1..9e3d1e23 100644 --- a/include/XSLT/impl/handler/xslt_item_container_handler.hpp +++ b/include/XSLT/impl/handler/xslt_item_container_handler.hpp @@ -3,7 +3,6 @@ #include "xslt_create_handler.hpp" #include "../xslt_text.hpp" -#include "xslt_value_validation.hpp" namespace Arabica { diff --git a/include/XSLT/impl/handler/xslt_key_handler.hpp b/include/XSLT/impl/handler/xslt_key_handler.hpp index 9c9756d0..71000afd 100644 --- a/include/XSLT/impl/handler/xslt_key_handler.hpp +++ b/include/XSLT/impl/handler/xslt_key_handler.hpp @@ -49,9 +49,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:key element must be empty"); + verifyNoCharacterData(ch, "xsl:key"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_namespace_alias_handler.hpp b/include/XSLT/impl/handler/xslt_namespace_alias_handler.hpp index aec447e1..20d383bb 100644 --- a/include/XSLT/impl/handler/xslt_namespace_alias_handler.hpp +++ b/include/XSLT/impl/handler/xslt_namespace_alias_handler.hpp @@ -61,9 +61,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:namespace-alias element must be empty"); + verifyNoCharacterData(ch, "xsl:namespace-alias"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_output_handler.hpp b/include/XSLT/impl/handler/xslt_output_handler.hpp index e03880b9..7b85f6b8 100644 --- a/include/XSLT/impl/handler/xslt_output_handler.hpp +++ b/include/XSLT/impl/handler/xslt_output_handler.hpp @@ -1,8 +1,6 @@ #ifndef ARABICA_XSLT_OUTPUT_HANDLER_HPP #define ARABICA_XSLT_OUTPUT_HANDLER_HPP -#include "xslt_value_validation.hpp" - namespace Arabica { namespace XSLT @@ -54,9 +52,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:output element must be empty"); + verifyNoCharacterData(ch, "xsl:output"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_sort_handler.hpp b/include/XSLT/impl/handler/xslt_sort_handler.hpp index 4dd8a561..bd0b11a6 100644 --- a/include/XSLT/impl/handler/xslt_sort_handler.hpp +++ b/include/XSLT/impl/handler/xslt_sort_handler.hpp @@ -67,9 +67,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:sort element must be empty"); + verifyNoCharacterData(ch, "xsl:sort"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_value_of_handler.hpp b/include/XSLT/impl/handler/xslt_value_of_handler.hpp index 8399e8b2..5ac6764e 100644 --- a/include/XSLT/impl/handler/xslt_value_of_handler.hpp +++ b/include/XSLT/impl/handler/xslt_value_of_handler.hpp @@ -48,9 +48,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator i = ch.begin(), e = ch.end(); i != e; ++i) - if(!Arabica::XML::is_space(*i)) - throw SAX::SAXException("xsl:value-of element must be empty"); + verifyNoCharacterData(ch, "xsl:value-of"); } // characters private: diff --git a/include/XSLT/impl/handler/xslt_value_validation.hpp b/include/XSLT/impl/handler/xslt_value_validation.hpp index 4fab6d2f..2d790a93 100644 --- a/include/XSLT/impl/handler/xslt_value_validation.hpp +++ b/include/XSLT/impl/handler/xslt_value_validation.hpp @@ -89,6 +89,17 @@ std::map gatherAttributes(const std::string& parentEle return results; } // validateAttributes +void verifyNoCharacterData(const std::string& ch, + const std::string& name) +{ + bool ok = true; + for(std::string::const_iterator i = ch.begin(), e = ch.end(); ok && i != e; ++i) + ok = Arabica::XML::is_space(*i); + + if(!ok) + throw SAX::SAXException(name + " element can not contain character data."); +} // verifyNoCharacterContent + } // namespace XSLT } // namespace Arabica #endif diff --git a/include/XSLT/impl/xslt_sort.hpp b/include/XSLT/impl/xslt_sort.hpp index 7803cddf..89bd64dd 100644 --- a/include/XSLT/impl/xslt_sort.hpp +++ b/include/XSLT/impl/xslt_sort.hpp @@ -2,7 +2,6 @@ #define ARABICA_XSLT_SORT_HPP #include -#include "handler/xslt_value_validation.hpp" namespace Arabica { diff --git a/include/XSLT/impl/xslt_stylesheet_compiler.hpp b/include/XSLT/impl/xslt_stylesheet_compiler.hpp index 4bd4f8c1..b0af28ab 100644 --- a/include/XSLT/impl/xslt_stylesheet_compiler.hpp +++ b/include/XSLT/impl/xslt_stylesheet_compiler.hpp @@ -8,6 +8,7 @@ #include "xslt_stylesheet_parser.hpp" #include "xslt_compiled_stylesheet.hpp" #include "xslt_compilation_context.hpp" +#include "handler/xslt_value_validation.hpp" #include "handler/xslt_template_handler.hpp" #include "handler/xslt_include_handler.hpp" #include "handler/xslt_output_handler.hpp" @@ -67,9 +68,7 @@ public: virtual void characters(const std::string& ch) { - for(std::string::const_iterator s = ch.begin(), e = ch.end(); s != e; ++s) - if(!Arabica::XML::is_space(*s)) - throw SAX::SAXException("stylesheet element can not contain character data :'" + ch +"'"); + verifyNoCharacterData(ch, "xsl:stylesheet/xsl:transform"); } // characters virtual void endDocument()