From 6081659b71d3dad318f510c76cc620998ebf563a Mon Sep 17 00:00:00 2001 From: jez Date: Fri, 24 Apr 2009 15:54:13 +0100 Subject: [PATCH] neatening --- .../XSLT/impl/xslt_stylesheet_compiler.hpp | 101 ++++++++++-------- 1 file changed, 59 insertions(+), 42 deletions(-) diff --git a/include/XSLT/impl/xslt_stylesheet_compiler.hpp b/include/XSLT/impl/xslt_stylesheet_compiler.hpp index d16facf1..141fc151 100755 --- a/include/XSLT/impl/xslt_stylesheet_compiler.hpp +++ b/include/XSLT/impl/xslt_stylesheet_compiler.hpp @@ -49,54 +49,16 @@ public: if(top_) { - if(namespaceURI != StylesheetConstant::NamespaceURI()) - throw SAX::SAXException("The source file does not look like a stylesheet."); - if(localName != "stylesheet" && localName != "transform") - throw SAX::SAXException("Top-level element must be 'stylesheet' or 'transform'."); - - static const ValueRule rules[] = { { "version", true, 0 }, - { "extension-element-prefixes", false, 0 }, - { "exclude-result-prefixes", false, 0 }, - { "id", false, 0 }, - { 0, false, 0 } }; - std::map attributes = gatherAttributes(qName, atts, rules); - if(attributes["version"] != StylesheetConstant::Version()) - throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer."); - if(!attributes["extension-element-prefixes"].empty()) - throw SAX::SAXException("Haven't implemented extension-element-prefixes yet"); - - top_ = false; - + startStylesheet(namespaceURI, localName, qName, atts); return; } // if(top_) if(namespaceURI == StylesheetConstant::NamespaceURI()) - { - if((localName == "import") || (localName == "include")) - { - include_stylesheet(namespaceURI, localName, qName, atts); - return; - } // if ... - - for(const ChildElement* c = allowedChildren; c->name != 0; ++c) - if(c->name == localName) - { - context_.push(0, - c->createHandler(context_), - namespaceURI, - qName, - localName, - atts); - return; - } // if ... - } // if ... + startXSLTElement(namespaceURI, localName, qName, atts); else if(!namespaceURI.empty()) - { ++foreign_; - return; - } // if(!namespaceURI.empty()) - - throw SAX::SAXException("xsl:stylesheet does not allow " + qName + " here."); + else + oops(qName); } // startElement virtual void endElement(const std::string& namespaceURI, @@ -124,6 +86,56 @@ public: } // endDocument private: + void startStylesheet(const std::string& namespaceURI, + const std::string& localName, + const std::string& qName, + const SAX::Attributes& atts) + { + if(namespaceURI != StylesheetConstant::NamespaceURI()) + throw SAX::SAXException("The source file does not look like a stylesheet."); + if(localName != "stylesheet" && localName != "transform") + throw SAX::SAXException("Top-level element must be 'stylesheet' or 'transform'."); + + static const ValueRule rules[] = { { "version", true, 0 }, + { "extension-element-prefixes", false, 0 }, + { "exclude-result-prefixes", false, 0 }, + { "id", false, 0 }, + { 0, false, 0 } }; + std::map attributes = gatherAttributes(qName, atts, rules); + if(attributes["version"] != StylesheetConstant::Version()) + throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer."); + if(!attributes["extension-element-prefixes"].empty()) + throw SAX::SAXException("Haven't implemented extension-element-prefixes yet"); + + top_ = false; + } // startStylesheet + + void startXSLTElement(const std::string& namespaceURI, + const std::string& localName, + const std::string& qName, + const SAX::Attributes& atts) + { + if((localName == "import") || (localName == "include")) + { + include_stylesheet(namespaceURI, localName, qName, atts); + return; + } // if ... + + for(const ChildElement* c = allowedChildren; c->name != 0; ++c) + if(c->name == localName) + { + context_.push(0, + c->createHandler(context_), + namespaceURI, + qName, + localName, + atts); + return; + } // if ... + + oops(qName); + } // startXSLTElement + void include_stylesheet(const std::string& namespaceURI, const std::string& localName, const std::string& qName, @@ -132,6 +144,11 @@ private: includer_.start_include(namespaceURI, localName, qName, atts); } // include_stylesheet + void oops(const std::string& qName) const + { + throw SAX::SAXException("xsl:stylesheet does not allow " + qName + " here."); + } // oops + CompilationContext& context_; SAX::DefaultHandler* child_; IncludeHandler includer_;