mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-30 08:38:15 +01:00
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:
parent
b22708f126
commit
297345f3c3
4 changed files with 59 additions and 7 deletions
|
@ -175,7 +175,7 @@ private:
|
||||||
return new DocumentFunction(parser_.currentBase(), argExprs);
|
return new DocumentFunction(parser_.currentBase(), argExprs);
|
||||||
// key
|
// key
|
||||||
if(name == "key")
|
if(name == "key")
|
||||||
return new KeyFunction(argExprs);
|
return new KeyFunction(stylesheet_.keys(), argExprs);
|
||||||
// format-number
|
// format-number
|
||||||
if((name == "current") && (current_allowed_))
|
if((name == "current") && (current_allowed_))
|
||||||
return new CurrentFunction(argExprs);
|
return new CurrentFunction(argExprs);
|
||||||
|
|
|
@ -92,6 +92,8 @@ public:
|
||||||
} // execute
|
} // execute
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
const DeclaredKeys& keys() const { return keys_; }
|
||||||
|
|
||||||
void add_template(Template* templat)
|
void add_template(Template* templat)
|
||||||
{
|
{
|
||||||
typedef std::vector<Arabica::XPath::MatchExpr<std::string> > MatchExprList;
|
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,
|
void add_key(const std::pair<std::string, std::string>& name,
|
||||||
Key* key)
|
Key* key)
|
||||||
{
|
{
|
||||||
std::cerr << "Added key " << name.second << std::endl;
|
keys_.add(name, key);
|
||||||
} // add_key
|
} // add_key
|
||||||
|
|
||||||
void output_settings(const Output::Settings& settings)
|
void output_settings(const Output::Settings& settings)
|
||||||
|
@ -316,6 +318,7 @@ private:
|
||||||
NamedTemplates named_templates_;
|
NamedTemplates named_templates_;
|
||||||
TemplateStack templates_;
|
TemplateStack templates_;
|
||||||
VariableDeclList topLevelVars_;
|
VariableDeclList topLevelVars_;
|
||||||
|
DeclaredKeys keys_;
|
||||||
ParamList params_;
|
ParamList params_;
|
||||||
|
|
||||||
mutable std::pair<std::string, std::string> current_mode_;
|
mutable std::pair<std::string, std::string> current_mode_;
|
||||||
|
|
|
@ -65,9 +65,13 @@ class KeyFunction : public Arabica::XPath::XPathFunction<std::string>
|
||||||
typedef Arabica::XPath::XPathFunction<std::string> baseT;
|
typedef Arabica::XPath::XPathFunction<std::string> baseT;
|
||||||
|
|
||||||
public:
|
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) :
|
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; }
|
virtual Arabica::XPath::ValueType type() const { return Arabica::XPath::NODE_SET; }
|
||||||
|
|
||||||
|
@ -83,6 +87,8 @@ public:
|
||||||
throw Arabica::XPath::UnsupportedException("key(" + keyname + ", " + id + ")");
|
throw Arabica::XPath::UnsupportedException("key(" + keyname + ", " + id + ")");
|
||||||
} // evaluate
|
} // evaluate
|
||||||
|
|
||||||
|
private:
|
||||||
|
const DeclaredKeys& keys_;
|
||||||
}; // class KeyFunction
|
}; // class KeyFunction
|
||||||
|
|
||||||
// string format-number(number, string, string?)
|
// string format-number(number, string, string?)
|
||||||
|
|
|
@ -19,14 +19,14 @@ public:
|
||||||
{
|
{
|
||||||
} // Key
|
} // 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_)
|
if(!populated_)
|
||||||
populate();
|
populate();
|
||||||
|
|
||||||
NodeMap::const_iterator f = nodes_.find(value);
|
NodeMap::const_iterator f = nodes_.find(value);
|
||||||
if(f == nodes_.end())
|
if(f == nodes_.end())
|
||||||
return DOM::Node<std::string>(0);
|
return Arabica::XPath::NodeSet<std::string>(0);
|
||||||
|
|
||||||
return f->second;
|
return f->second;
|
||||||
} // lookup
|
} // lookup
|
||||||
|
@ -42,10 +42,53 @@ private:
|
||||||
Arabica::XPath::XPathExpression<std::string> use_;
|
Arabica::XPath::XPathExpression<std::string> use_;
|
||||||
mutable bool populated_;
|
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_;
|
NodeMap nodes_;
|
||||||
}; // class Key
|
}; // 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 XSLT
|
||||||
} // namespace Arabica
|
} // namespace Arabica
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue