started filling out xsl:key and keys. need to do a bit of refactoring around QNames now, to make everything a little easier

This commit is contained in:
jez 2009-02-18 09:36:41 +00:00
parent b22708f126
commit 297345f3c3
4 changed files with 59 additions and 7 deletions

View file

@ -175,7 +175,7 @@ private:
return new DocumentFunction(parser_.currentBase(), argExprs);
// key
if(name == "key")
return new KeyFunction(argExprs);
return new KeyFunction(stylesheet_.keys(), argExprs);
// format-number
if((name == "current") && (current_allowed_))
return new CurrentFunction(argExprs);

View file

@ -92,6 +92,8 @@ public:
} // execute
////////////////////////////////////////
const DeclaredKeys& keys() const { return keys_; }
void add_template(Template* templat)
{
typedef std::vector<Arabica::XPath::MatchExpr<std::string> > MatchExprList;
@ -125,7 +127,7 @@ public:
void add_key(const std::pair<std::string, std::string>& name,
Key* key)
{
std::cerr << "Added key " << name.second << std::endl;
keys_.add(name, key);
} // add_key
void output_settings(const Output::Settings& settings)
@ -316,6 +318,7 @@ private:
NamedTemplates named_templates_;
TemplateStack templates_;
VariableDeclList topLevelVars_;
DeclaredKeys keys_;
ParamList params_;
mutable std::pair<std::string, std::string> current_mode_;

View file

@ -65,9 +65,13 @@ class KeyFunction : public Arabica::XPath::XPathFunction<std::string>
typedef Arabica::XPath::XPathFunction<std::string> baseT;
public:
KeyFunction(/* the keys, */
KeyFunction(const DeclaredKeys& keys,
/* also need to pass current namespace context, so can resolve qnames, */
const std::vector<Arabica::XPath::XPathExpression<std::string> >& args) :
Arabica::XPath::XPathFunction<std::string>(2, 2, args) { }
Arabica::XPath::XPathFunction<std::string>(2, 2, args),
keys_(keys)
{
} // KeyFunction
virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::NODE_SET; }
@ -83,6 +87,8 @@ public:
throw Arabica::XPath::UnsupportedException("key(" + keyname + ", " + id + ")");
} // evaluate
private:
const DeclaredKeys& keys_;
}; // class KeyFunction
// string format-number(number, string, string?)

View file

@ -19,14 +19,14 @@ public:
{
} // Key
Arabica::DOM::Node<std::string> lookup(const std::string& value) const
Arabica::XPath::NodeSet<std::string> lookup(const std::string& value) const
{
if(!populated_)
populate();
NodeMap::const_iterator f = nodes_.find(value);
if(f == nodes_.end())
return DOM::Node<std::string>(0);
return Arabica::XPath::NodeSet<std::string>(0);
return f->second;
} // lookup
@ -42,10 +42,53 @@ private:
Arabica::XPath::XPathExpression<std::string> use_;
mutable bool populated_;
typedef std::map<std::string, Arabica::DOM::Node<std::string> > NodeMap;
typedef std::map<std::string, Arabica::XPath::NodeSet<std::string> > NodeMap;
NodeMap nodes_;
}; // class Key
class DeclaredKeys
{
public:
DeclaredKeys() { }
~DeclaredKeys()
{
for(Keys::const_iterator i = keys_.begin(), ie = keys_.end(); i != ie; ++i)
for(KeyList::const_iterator k = i->second.begin(), ke = i->second.end(); k != ke; ++k)
delete (*k);
} // ~DeclaredKeys
void add(const std::pair<std::string, std::string>& name, Key* key)
{
keys_[name].push_back(key);
} // add_key
Arabica::XPath::NodeSet<std::string> lookup(const std::pair<std::string, std::string>& name,
const std::string& id) const
{
const Keys::const_iterator k = keys_.find(name);
if(k == keys_.end())
throw SAX::SAXException("No key named '" + name.second + "' has been defined.");
//if(k->second.size() == 0)
return k->second[0]->lookup(id);
//Arabica::XPath::NodeSet<std::string> nodes;
//for(KeyList::const_iterator k = i->second.begin(), ke = i->second.end(); k != ke; ++k)
//nodes.a
//return k->second.lookup(id);
} // lookup
private:
typedef std::vector<Key*> KeyList;
typedef std::map<std::pair<std::string, std::string>, KeyList> Keys;
Keys keys_;
DeclaredKeys(const DeclaredKeys&);
DeclaredKeys& operator=(const DeclaredKeys&);
bool operator==(const DeclaredKeys&) const;
}; // class DeclaredKeys
} // namespace XSLT
} // namespace Arabica