mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-17 18:12:04 +01:00
XSLT: template names are now QNames
This commit is contained in:
parent
32ea3d8523
commit
b45e512845
5 changed files with 35 additions and 24 deletions
|
@ -25,11 +25,12 @@ public:
|
|||
{
|
||||
if(callTemplate_ == 0)
|
||||
{
|
||||
const std::string& name = atts.getValue("name");
|
||||
if(name == "")
|
||||
throw SAX::SAXException("xsl:call-template must have a name attribute.");
|
||||
if(atts.getLength() > 1)
|
||||
throw SAX::SAXException("xsl:call-template may only have a name attribute.");
|
||||
static const ValueRule rules[] = { { "name", true, 0 },
|
||||
{ 0, false, 0} };
|
||||
|
||||
std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules);
|
||||
|
||||
std::pair<std::string, std::string> name = context_.processQName(attrs["name"]);
|
||||
|
||||
callTemplate_ = new CallTemplate(name);
|
||||
return;
|
||||
|
|
|
@ -31,15 +31,19 @@ protected:
|
|||
if((atts.getValue("mode") != "") && (match == ""))
|
||||
throw SAX::SAXException("xsl:template may not have a mode without a match");
|
||||
|
||||
std::pair<std::string, std::string> name;
|
||||
if(atts.getValue("name") != "")
|
||||
name = context().processQName(atts.getValue("name"));
|
||||
|
||||
if(match == "")
|
||||
return new Template(atts.getValue("name"),
|
||||
atts.getValue("mode"),
|
||||
atts.getValue("priority"));
|
||||
return new Template(name,
|
||||
atts.getValue("mode"),
|
||||
atts.getValue("priority"));
|
||||
|
||||
return new Template(context().xpath().compile_match(match),
|
||||
atts.getValue("name"),
|
||||
atts.getValue("mode"),
|
||||
atts.getValue("priority"));
|
||||
name,
|
||||
atts.getValue("mode"),
|
||||
atts.getValue("priority"));
|
||||
} // createContainer
|
||||
|
||||
virtual bool createChild(const std::string& namespaceURI,
|
||||
|
|
|
@ -13,7 +13,7 @@ class CallTemplate : public Item,
|
|||
public WithParamable
|
||||
{
|
||||
public:
|
||||
CallTemplate(const std::string& name) :
|
||||
CallTemplate(const std::pair<std::string, std::string>& name) :
|
||||
name_(name)
|
||||
{
|
||||
} // CallTemplate
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
} // execute
|
||||
|
||||
private:
|
||||
const std::string name_;
|
||||
const std::pair<std::string, std::string> name_;
|
||||
}; // class CallTemplate
|
||||
|
||||
} // namespace XSLT
|
||||
|
|
|
@ -97,7 +97,10 @@ public:
|
|||
|
||||
if(named_templates_.find(templat->name()) != named_templates_.end())
|
||||
{
|
||||
std::cerr << "Template named '" << templat->name() << "' already defined" << std::endl;
|
||||
std::cerr << "Template named '";
|
||||
if(!templat->name().first.empty())
|
||||
std::cerr << "{" << templat->name().first << "}";
|
||||
std::cerr << templat->name().second << "' already defined" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -164,14 +167,17 @@ public:
|
|||
doApplyTemplates(node, context, mode, 0);
|
||||
} // applyTemplates
|
||||
|
||||
void callTemplate(const std::string& name, const DOM::Node<std::string>& node, ExecutionContext& context) const
|
||||
void callTemplate(const std::pair<std::string, std::string>& name, const DOM::Node<std::string>& node, ExecutionContext& context) const
|
||||
{
|
||||
StackFrame frame(context);
|
||||
|
||||
NamedTemplates::const_iterator t = named_templates_.find(name);
|
||||
if(t == named_templates_.end())
|
||||
{
|
||||
std::cerr << "No template named '" << name << "'. I should be a compile time-error!" << std::endl;
|
||||
std::cerr << "No template named '";
|
||||
if(!name.first.empty())
|
||||
std::cerr << "{" << name.first << "}";
|
||||
std::cerr << name.second << "'. I should be a compile time-error!" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -281,7 +287,7 @@ private:
|
|||
typedef std::vector<MatchTemplate> MatchTemplates;
|
||||
typedef std::map<std::string, MatchTemplates> ModeTemplates;
|
||||
typedef std::vector<ModeTemplates> TemplateStack;
|
||||
typedef std::map<std::string, Template*> NamedTemplates;
|
||||
typedef std::map<std::pair<std::string, std::string>, Template*> NamedTemplates;
|
||||
|
||||
TemplateList all_templates_;
|
||||
NamedTemplates named_templates_;
|
||||
|
|
|
@ -11,9 +11,9 @@ namespace XSLT
|
|||
class Template : public ItemContainer
|
||||
{
|
||||
public:
|
||||
Template(const std::string& name,
|
||||
const std::string& mode,
|
||||
const std::string& priority) :
|
||||
Template(const std::pair<std::string, std::string>& name,
|
||||
const std::string& mode,
|
||||
const std::string& priority) :
|
||||
matches_(),
|
||||
name_(name),
|
||||
mode_(mode)
|
||||
|
@ -21,7 +21,7 @@ public:
|
|||
} // Template
|
||||
|
||||
Template(const std::vector<Arabica::XPath::MatchExpr<std::string> >& matches,
|
||||
const std::string& name,
|
||||
const std::pair<std::string, std::string>& name,
|
||||
const std::string& mode,
|
||||
const std::string& priority) :
|
||||
matches_(matches),
|
||||
|
@ -46,13 +46,13 @@ public:
|
|||
} // execute
|
||||
|
||||
const std::vector<Arabica::XPath::MatchExpr<std::string> >& compiled_matches() const { return matches_; }
|
||||
bool has_name() const { return !name_.empty(); }
|
||||
const std::string& name() const { return name_; }
|
||||
bool has_name() const { return !name_.second.empty(); }
|
||||
const std::pair<std::string, std::string>& name() const { return name_; }
|
||||
const std::string& mode() const { return mode_; }
|
||||
|
||||
private:
|
||||
std::vector<Arabica::XPath::MatchExpr<std::string> > matches_;
|
||||
std::string name_;
|
||||
std::pair<std::string, std::string> name_;
|
||||
std::string mode_;
|
||||
}; // class Template
|
||||
|
||||
|
|
Loading…
Reference in a new issue