mirror of
https://github.com/jezhiggins/arabica
synced 2024-11-15 19:48:00 +01:00
attribute and call_tempalte
This commit is contained in:
parent
e3a06bec80
commit
d68a9240ce
5 changed files with 48 additions and 44 deletions
|
@ -9,34 +9,33 @@ namespace Arabica
|
|||
namespace XSLT
|
||||
{
|
||||
|
||||
class AttributeHandler : public ItemContainerHandler<Attribute>
|
||||
template<class string_type, class string_adaptor>
|
||||
class AttributeHandler : public ItemContainerHandler<Attribute<string_type, string_adaptor> >
|
||||
{
|
||||
public:
|
||||
AttributeHandler(CompilationContext<std::string>& context) :
|
||||
ItemContainerHandler<Attribute>(context)
|
||||
AttributeHandler(CompilationContext<string_type, string_adaptor>& context) :
|
||||
ItemContainerHandler<Attribute<string_type, string_adaptor> >(context)
|
||||
{
|
||||
} // AttributeHandler
|
||||
|
||||
protected:
|
||||
virtual Attribute* createContainer(const std::string& /* namespaceURI */,
|
||||
const std::string& /* localName */,
|
||||
const std::string& qName,
|
||||
const SAX::Attributes<std::string>& atts)
|
||||
virtual Attribute<string_type, string_adaptor>* createContainer(const string_type& /* namespaceURI */,
|
||||
const string_type& /* localName */,
|
||||
const string_type& qName,
|
||||
const SAX::Attributes<string_type, string_adaptor>& atts)
|
||||
{
|
||||
static const ValueRule rules[] = { { "name", true, 0, 0 },
|
||||
{ "namespace", false, "", 0 },
|
||||
{ 0, false, 0, 0 } };
|
||||
|
||||
std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules);
|
||||
std::map<string_type, string_type> attrs = gatherAttributes(qName, atts, rules);
|
||||
|
||||
Arabica::XPath::XPathExpressionPtr<std::string> name = context().xpath_attribute_value_template(attrs["name"]);
|
||||
Arabica::XPath::XPathExpressionPtr<string_type> name = context().xpath_attribute_value_template(attrs["name"]);
|
||||
|
||||
if(attrs["namespace"] == "")
|
||||
return new Attribute(name,
|
||||
context().inScopeNamespaces());
|
||||
return new Attribute<string_type, string_adaptor>(name, context().inScopeNamespaces());
|
||||
|
||||
return new Attribute(name,
|
||||
context().xpath_attribute_value_template(attrs["namespace"]));
|
||||
return new Attribute<string_type, string_adaptor>(name, context().xpath_attribute_value_template(attrs["namespace"]));
|
||||
} // createContainer
|
||||
}; // class AttributeHandler
|
||||
|
||||
|
|
|
@ -9,30 +9,31 @@ namespace Arabica
|
|||
namespace XSLT
|
||||
{
|
||||
|
||||
class CallTemplateHandler : public SAX::DefaultHandler<std::string>
|
||||
template<class string_type, class string_adaptor>
|
||||
class CallTemplateHandler : public SAX::DefaultHandler<string_type, string_adaptor>
|
||||
{
|
||||
public:
|
||||
CallTemplateHandler(CompilationContext<std::string>& context) :
|
||||
CallTemplateHandler(CompilationContext<string_type, string_adaptor>& context) :
|
||||
context_(context),
|
||||
callTemplate_(0)
|
||||
{
|
||||
} // CallTemplateHandler
|
||||
|
||||
virtual void startElement(const std::string& namespaceURI,
|
||||
const std::string& localName,
|
||||
const std::string& qName,
|
||||
const SAX::Attributes<std::string>& atts)
|
||||
virtual void startElement(const string_type& namespaceURI,
|
||||
const string_type& localName,
|
||||
const string_type& qName,
|
||||
const SAX::Attributes<string_type, string_adaptor>& atts)
|
||||
{
|
||||
if(callTemplate_ == 0)
|
||||
{
|
||||
static const ValueRule rules[] = { { "name", true, 0, 0 },
|
||||
{ 0, false, 0, 0 } };
|
||||
|
||||
std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules);
|
||||
std::map<string_type, string_type> attrs = gatherAttributes(qName, atts, rules);
|
||||
|
||||
std::string name = context_.processInternalQName(attrs["name"]).clarkName();
|
||||
string_type name = context_.processInternalQName(attrs["name"]).clarkName();
|
||||
|
||||
callTemplate_ = new CallTemplate(name);
|
||||
callTemplate_ = new CallTemplate<string_type, string_adaptor>(name);
|
||||
return;
|
||||
} // if(callTemplate_ == 0)
|
||||
|
||||
|
@ -50,21 +51,21 @@ public:
|
|||
throw SAX::SAXException("xsl:call-template can only contain xsl:sort and xsl:with-param elements.");
|
||||
} // startElement
|
||||
|
||||
virtual void endElement(const std::string& /* namespaceURI */,
|
||||
const std::string& /* localName */,
|
||||
const std::string& /* qName */)
|
||||
virtual void endElement(const string_type& /* namespaceURI */,
|
||||
const string_type& /* localName */,
|
||||
const string_type& /* qName */)
|
||||
{
|
||||
context_.parentContainer().add_item(callTemplate_);
|
||||
context_.pop();
|
||||
} // endElement
|
||||
|
||||
virtual void characters(const std::string& /* ch */)
|
||||
virtual void characters(const string_type& /* ch */)
|
||||
{
|
||||
} // characters
|
||||
|
||||
private:
|
||||
CompilationContext<std::string>& context_;
|
||||
CallTemplate* callTemplate_;
|
||||
CompilationContext<string_type, string_adaptor>& context_;
|
||||
CallTemplate<string_type, string_adaptor>* callTemplate_;
|
||||
}; // class CallTemplateHandler
|
||||
|
||||
} // namespace XSLT
|
||||
|
|
|
@ -140,8 +140,8 @@ const ChildElement* AllowedChildren()
|
|||
{
|
||||
{ "apply-imports", CreateHandler<ApplyImportsHandler> },
|
||||
{ "apply-templates", CreateHandler<ApplyTemplatesHandler> },
|
||||
{ "attribute", CreateHandler<AttributeHandler> },
|
||||
{ "call-template", CreateHandler<CallTemplateHandler> },
|
||||
{ "attribute", CreateHandler<AttributeHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
|
||||
{ "call-template", CreateHandler<CallTemplateHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
|
||||
{ "choose", CreateHandler<ChooseHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
|
||||
{ "comment", CreateHandler<CommentHandler<std::string, Arabica::default_string_adaptor<std::string> > > },
|
||||
{ "copy", CreateHandler<CopyHandler> },
|
||||
|
|
|
@ -8,18 +8,19 @@ namespace Arabica
|
|||
namespace XSLT
|
||||
{
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
class Attribute : public ItemContainer
|
||||
{
|
||||
public:
|
||||
Attribute(const Arabica::XPath::XPathExpressionPtr<std::string>& name,
|
||||
const Arabica::XPath::XPathExpressionPtr<std::string>& name_space) :
|
||||
Attribute(const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& name,
|
||||
const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& name_space) :
|
||||
name_(name),
|
||||
namespace_(name_space)
|
||||
{
|
||||
} // Attribute
|
||||
|
||||
Attribute(const Arabica::XPath::XPathExpressionPtr<std::string>& name,
|
||||
const std::map<std::string, std::string>& namespaces) :
|
||||
Attribute(const Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor>& name,
|
||||
const std::map<string_type, string_type>& namespaces) :
|
||||
name_(name),
|
||||
namespaces_(namespaces)
|
||||
{
|
||||
|
@ -27,13 +28,14 @@ public:
|
|||
|
||||
virtual ~Attribute() { }
|
||||
|
||||
virtual void execute(const DOM::Node<std::string>& node, ExecutionContext& context) const
|
||||
virtual void execute(const DOM::Node<string_type, string_adaptor>& node,
|
||||
ExecutionContext& context) const
|
||||
{
|
||||
std::string name = name_->evaluateAsString(node, context.xpathContext());
|
||||
string_type name = name_->evaluateAsString(node, context.xpathContext());
|
||||
if(name.empty())
|
||||
throw SAX::SAXException("xsl:attribute name attribute must evaluate to a valid element name");
|
||||
|
||||
std::string namesp;
|
||||
string_type namesp;
|
||||
|
||||
if(namespace_ != 0)
|
||||
namesp = namespace_->evaluateAsString(node, context.xpathContext());
|
||||
|
@ -42,7 +44,7 @@ public:
|
|||
QName qn = QName::create(name);
|
||||
if(!qn.prefix.empty())
|
||||
{
|
||||
std::map<std::string, std::string>::const_iterator ns = namespaces_.find(qn.prefix);
|
||||
std::map<string_type, string_type>::const_iterator ns = namespaces_.find(qn.prefix);
|
||||
if(ns == namespaces_.end())
|
||||
throw SAX::SAXException("xsl:attribute Runtime Error - Undeclared prefix " + qn.prefix);
|
||||
namesp = ns->second;
|
||||
|
@ -56,9 +58,9 @@ public:
|
|||
} // execute
|
||||
|
||||
private:
|
||||
Arabica::XPath::XPathExpressionPtr<std::string> name_;
|
||||
Arabica::XPath::XPathExpressionPtr<std::string> namespace_;
|
||||
std::map<std::string, std::string> namespaces_;
|
||||
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> name_;
|
||||
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> namespace_;
|
||||
std::map<string_type, string_type> namespaces_;
|
||||
}; // class Attribute
|
||||
|
||||
} // namespace XSLT
|
||||
|
|
|
@ -9,23 +9,25 @@ namespace Arabica
|
|||
namespace XSLT
|
||||
{
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
class CallTemplate : public Item,
|
||||
public WithParamable
|
||||
{
|
||||
public:
|
||||
CallTemplate(const std::string& name) :
|
||||
CallTemplate(const string_type& name) :
|
||||
name_(name)
|
||||
{
|
||||
} // CallTemplate
|
||||
|
||||
virtual void execute(const DOM::Node<std::string>& node, ExecutionContext& context) const
|
||||
virtual void execute(const DOM::Node<string_type, string_adaptor>& node,
|
||||
ExecutionContext& context) const
|
||||
{
|
||||
ParamPasser passer(*this, node, context);
|
||||
context.stylesheet().callTemplate(name_, node, context);
|
||||
} // execute
|
||||
|
||||
private:
|
||||
const std::string name_;
|
||||
const string_type name_;
|
||||
}; // class CallTemplate
|
||||
|
||||
} // namespace XSLT
|
||||
|
|
Loading…
Reference in a new issue