mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-17 18:12:04 +01:00
keys now look something up. yay!
This commit is contained in:
parent
ff835d03c0
commit
8cb5109ac1
3 changed files with 29 additions and 10 deletions
|
@ -37,7 +37,7 @@ template<class axis_walker, class string_type, class string_adaptor>
|
|||
AxisWalker<string_type, string_adaptor>* CreateAxis(const DOM::Node<string_type, string_adaptor>& context) { return new axis_walker(context); }
|
||||
} // namespace impl
|
||||
|
||||
template<class string_type, class string_adaptor>
|
||||
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
|
||||
class AxisEnumerator
|
||||
{
|
||||
typedef impl::AxisWalker<string_type, string_adaptor>* (*CreateAxisPtr)(const DOM::Node<string_type, string_adaptor>& context);
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
std::string id = a1.asString();
|
||||
std::string clarkName = XML::QualifiedName<std::string>::parseQName(keyname, true, UriMapper(namespaces_)).clarkName();
|
||||
|
||||
return new Arabica::XPath::NodeSetValue<std::string>(keys_.lookup(clarkName, id));
|
||||
return new Arabica::XPath::NodeSetValue<std::string>(keys_.lookup(clarkName, id, executionContext));
|
||||
} // evaluate
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef ARABICA_XSLT_KEY_HPP
|
||||
#define ARABICA_XSLT_KEY_HPP
|
||||
|
||||
#include "xslt_execution_context.hpp"
|
||||
|
||||
namespace Arabica
|
||||
{
|
||||
namespace XSLT
|
||||
|
@ -19,10 +21,11 @@ public:
|
|||
{
|
||||
} // Key
|
||||
|
||||
Arabica::XPath::NodeSet<std::string> lookup(const std::string& value) const
|
||||
Arabica::XPath::NodeSet<std::string> lookup(const std::string& value,
|
||||
const Arabica::XPath::ExecutionContext<std::string>& context) const
|
||||
{
|
||||
if(!populated_)
|
||||
populate();
|
||||
populate(context);
|
||||
|
||||
NodeMap::const_iterator f = nodes_.find(value);
|
||||
if(f == nodes_.end())
|
||||
|
@ -32,9 +35,24 @@ public:
|
|||
} // lookup
|
||||
|
||||
private:
|
||||
void populate() const
|
||||
void populate(const Arabica::XPath::ExecutionContext<std::string>& context) const
|
||||
{
|
||||
std::cerr << "Populating key map " << std::endl;
|
||||
typedef XPath::AxisEnumerator<std::string> AxisEnum;
|
||||
|
||||
DOM::Node<std::string> current = XPath::impl::get_owner_document(context.currentNode());
|
||||
|
||||
for(AxisEnum ae(current, XPath::DESCENDANT_OR_SELF); *ae != 0; ++ae)
|
||||
{
|
||||
DOM::Node<std::string> node = *ae;
|
||||
for(MatchExprList::const_iterator me = matches_.begin(), mee = matches_.end(); me != mee; ++me)
|
||||
if(me->evaluate(node, context))
|
||||
{
|
||||
std::string id = use_.evaluateAsString(node, context);
|
||||
nodes_[id].push_back(node);
|
||||
break;
|
||||
} // if ...
|
||||
} // for
|
||||
|
||||
populated_ = true;
|
||||
} // populate
|
||||
|
||||
|
@ -43,7 +61,7 @@ private:
|
|||
mutable bool populated_;
|
||||
|
||||
typedef std::map<std::string, Arabica::XPath::NodeSet<std::string> > NodeMap;
|
||||
NodeMap nodes_;
|
||||
mutable NodeMap nodes_;
|
||||
}; // class Key
|
||||
|
||||
class DeclaredKeys
|
||||
|
@ -63,18 +81,19 @@ public:
|
|||
} // add_key
|
||||
|
||||
Arabica::XPath::NodeSet<std::string> lookup(const std::string& name,
|
||||
const std::string& id) const
|
||||
const std::string& id,
|
||||
const Arabica::XPath::ExecutionContext<std::string>& context) const
|
||||
{
|
||||
const Keys::const_iterator k = keys_.find(name);
|
||||
if(k == keys_.end())
|
||||
throw SAX::SAXException("No key named '" + name + "' has been defined.");
|
||||
|
||||
if(k->second.size() == 1)
|
||||
return k->second[0]->lookup(id);
|
||||
return k->second[0]->lookup(id, context);
|
||||
|
||||
Arabica::XPath::NodeSet<std::string> nodes;
|
||||
for(KeyList::const_iterator key = k->second.begin(), keye = k->second.end(); key != keye; ++key)
|
||||
nodes.push_back((*key)->lookup(id));
|
||||
nodes.push_back((*key)->lookup(id, context));
|
||||
nodes.sort();
|
||||
return nodes;
|
||||
} // lookup
|
||||
|
|
Loading…
Reference in a new issue