mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-30 08:38:15 +01:00
inline elements
This commit is contained in:
parent
1dd953346b
commit
ab2ae612c9
4 changed files with 47 additions and 41 deletions
|
@ -10,21 +10,22 @@ namespace Arabica
|
||||||
namespace XSLT
|
namespace XSLT
|
||||||
{
|
{
|
||||||
|
|
||||||
class InlineElementHandler : public ItemContainerHandler<InlineElement>
|
template<class string_type, class string_adaptor>
|
||||||
|
class InlineElementHandler : public ItemContainerHandler<InlineElement<string_type, string_adaptor> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InlineElementHandler(CompilationContext<std::string>& context) :
|
InlineElementHandler(CompilationContext<string_type, string_adaptor>& context) :
|
||||||
ItemContainerHandler<InlineElement>(context)
|
ItemContainerHandler<InlineElement<string_type, string_adaptor> >(context)
|
||||||
{
|
{
|
||||||
} // InlineElementHandler
|
} // InlineElementHandler
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual InlineElement* createContainer(const std::string& namespaceURI,
|
virtual InlineElement<string_type, string_adaptor>* createContainer(const string_type& namespaceURI,
|
||||||
const std::string& localName,
|
const string_type& localName,
|
||||||
const std::string& qName,
|
const string_type& qName,
|
||||||
const SAX::Attributes<std::string>& atts)
|
const SAX::Attributes<string_type, string_adaptor>& atts)
|
||||||
{
|
{
|
||||||
std::vector<InlineAttribute> inlineAtts;
|
std::vector<InlineAttribute<string_type, string_adaptor> > inlineAtts;
|
||||||
for(int i = 0; i != atts.getLength(); ++i)
|
for(int i = 0; i != atts.getLength(); ++i)
|
||||||
{
|
{
|
||||||
if(atts.getQName(i).find("xmlns:") == 0)
|
if(atts.getQName(i).find("xmlns:") == 0)
|
||||||
|
@ -32,45 +33,48 @@ protected:
|
||||||
if(atts.getURI(i) == StylesheetConstant::NamespaceURI())
|
if(atts.getURI(i) == StylesheetConstant::NamespaceURI())
|
||||||
continue;
|
continue;
|
||||||
if(!context().isRemapped(atts.getURI(i)))
|
if(!context().isRemapped(atts.getURI(i)))
|
||||||
inlineAtts.push_back(InlineAttribute(atts.getQName(i),
|
inlineAtts.push_back(InlineAttribute<string_type, string_adaptor>(atts.getQName(i),
|
||||||
atts.getURI(i),
|
atts.getURI(i),
|
||||||
context().xpath_attribute_value_template(atts.getValue(i))));
|
context().xpath_attribute_value_template(atts.getValue(i))));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::pair<std::string, std::string> remap = context().remappedNamespace(atts.getURI(i));
|
std::pair<string_type, string_type> remap = context().remappedNamespace(atts.getURI(i));
|
||||||
if(remap.first.empty() && !remap.second.empty())
|
if(remap.first.empty() && !remap.second.empty())
|
||||||
remap.first = context().autoNamespacePrefix();
|
remap.first = context().autoNamespacePrefix();
|
||||||
std::string name = remap.first + ":" + atts.getLocalName(i);
|
string_type name = remap.first + ":" + atts.getLocalName(i);
|
||||||
inlineAtts.push_back(InlineAttribute(name,
|
inlineAtts.push_back(InlineAttribute<string_type, string_adaptor>(name,
|
||||||
remap.second,
|
remap.second,
|
||||||
context().xpath_attribute_value_template(atts.getValue(i))));
|
context().xpath_attribute_value_template(atts.getValue(i))));
|
||||||
} // if ...
|
} // if ...
|
||||||
} // for ...
|
} // for ...
|
||||||
|
|
||||||
if(!context().isRemapped(namespaceURI))
|
if(!context().isRemapped(namespaceURI))
|
||||||
return new InlineElement(qName, namespaceURI, inlineAtts);
|
return new InlineElement<string_type, string_adaptor>(qName, namespaceURI, inlineAtts);
|
||||||
|
|
||||||
const std::pair<std::string, std::string>& remap = context().remappedNamespace(namespaceURI);
|
const std::pair<string_type, string_type>& remap = context().remappedNamespace(namespaceURI);
|
||||||
std::string name = remap.first + ":" + localName;
|
string_type name = remap.first + ":" + localName;
|
||||||
return new InlineElement(name, remap.second, inlineAtts);
|
return new InlineElement<string_type, string_adaptor>(name, remap.second, inlineAtts);
|
||||||
} // createContainer
|
} // createContainer
|
||||||
}; // class InlineElementHandler
|
}; // class InlineElementHandler
|
||||||
|
|
||||||
class LREStylesheetHandler : public InlineElementHandler
|
|
||||||
|
template<class string_type, class string_adaptor>
|
||||||
|
class LREStylesheetHandler : public InlineElementHandler<string_type, string_adaptor>
|
||||||
{
|
{
|
||||||
|
typedef InlineElementHandler<string_type, string_adaptor> baseT;
|
||||||
public:
|
public:
|
||||||
LREStylesheetHandler(CompilationContext<std::string>& context, Template* lreStylesheet) :
|
LREStylesheetHandler(CompilationContext<string_type, string_adaptor>& context, Template* lreStylesheet) :
|
||||||
InlineElementHandler(context),
|
baseT(context),
|
||||||
lreStylesheet_(lreStylesheet)
|
lreStylesheet_(lreStylesheet)
|
||||||
{
|
{
|
||||||
} // LREStylesheetHandler
|
} // LREStylesheetHandler
|
||||||
|
|
||||||
virtual void endElement(const std::string& namespaceURI,
|
virtual void endElement(const string_type& namespaceURI,
|
||||||
const std::string& localName,
|
const string_type& localName,
|
||||||
const std::string& qName)
|
const string_type& qName)
|
||||||
{
|
{
|
||||||
context().stylesheet().add_template(lreStylesheet_);
|
baseT::context().stylesheet().add_template(lreStylesheet_);
|
||||||
InlineElementHandler::endElement(namespaceURI, localName, qName);
|
baseT::endElement(namespaceURI, localName, qName);
|
||||||
} // endElement
|
} // endElement
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -163,7 +163,7 @@ const ChildElement* AllowedChildren()
|
||||||
|
|
||||||
SAX::DefaultHandler<std::string>* createInlineElementHandler(CompilationContext<std::string>& context)
|
SAX::DefaultHandler<std::string>* createInlineElementHandler(CompilationContext<std::string>& context)
|
||||||
{
|
{
|
||||||
return new InlineElementHandler(context);
|
return new InlineElementHandler<std::string, Arabica::default_string_adaptor<std::string> >(context);
|
||||||
} // InlineElementHandler
|
} // InlineElementHandler
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,13 @@ namespace Arabica
|
||||||
namespace XSLT
|
namespace XSLT
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template<class string_type, class string_adaptor>
|
||||||
class InlineAttribute
|
class InlineAttribute
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InlineAttribute(const std::string& name,
|
InlineAttribute(const string_type& name,
|
||||||
const std::string& name_space,
|
const string_type& name_space,
|
||||||
Arabica::XPath::XPathExpressionPtr<std::string> value) :
|
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> value) :
|
||||||
name_(name),
|
name_(name),
|
||||||
namespace_(name_space),
|
namespace_(name_space),
|
||||||
value_(value)
|
value_(value)
|
||||||
|
@ -36,7 +37,7 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
} // operator==
|
} // operator==
|
||||||
|
|
||||||
void execute(const DOM::Node<std::string>& node, ExecutionContext& context) const
|
void execute(const DOM::Node<string_type, string_adaptor>& node, ExecutionContext& context) const
|
||||||
{
|
{
|
||||||
context.sink().start_attribute(name_, namespace_);
|
context.sink().start_attribute(name_, namespace_);
|
||||||
context.sink().characters(value_->evaluateAsString(node, context.xpathContext()));
|
context.sink().characters(value_->evaluateAsString(node, context.xpathContext()));
|
||||||
|
@ -44,17 +45,18 @@ public:
|
||||||
} // execute
|
} // execute
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
string_type name_;
|
||||||
std::string namespace_;
|
string_type namespace_;
|
||||||
Arabica::XPath::XPathExpressionPtr<std::string> value_;
|
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> value_;
|
||||||
}; // class InlineAttribute
|
}; // class InlineAttribute
|
||||||
|
|
||||||
|
template<class string_type, class string_adaptor>
|
||||||
class InlineElement : public ItemContainer
|
class InlineElement : public ItemContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InlineElement(const std::string& name,
|
InlineElement(const string_type& name,
|
||||||
const std::string& name_space,
|
const string_type& name_space,
|
||||||
const std::vector<InlineAttribute>& attrs) :
|
const std::vector<InlineAttribute<string_type, string_adaptor> >& attrs) :
|
||||||
name_(name),
|
name_(name),
|
||||||
namespace_(name_space),
|
namespace_(name_space),
|
||||||
attrs_(attrs)
|
attrs_(attrs)
|
||||||
|
@ -63,11 +65,11 @@ public:
|
||||||
|
|
||||||
virtual ~InlineElement() { }
|
virtual ~InlineElement() { }
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
if(context.sink().start_element(name_, namespace_))
|
if(context.sink().start_element(name_, namespace_))
|
||||||
{
|
{
|
||||||
for(std::vector<InlineAttribute>::const_iterator a = attrs_.begin(), ae = attrs_.end(); a != ae; ++a)
|
for(typename std::vector<InlineAttribute<string_type, string_adaptor> >::const_iterator a = attrs_.begin(), ae = attrs_.end(); a != ae; ++a)
|
||||||
a->execute(node, context);
|
a->execute(node, context);
|
||||||
|
|
||||||
ChainStackFrame frame(context);
|
ChainStackFrame frame(context);
|
||||||
|
@ -77,9 +79,9 @@ public:
|
||||||
} // execute
|
} // execute
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
string_type name_;
|
||||||
std::string namespace_;
|
string_type namespace_;
|
||||||
std::vector<InlineAttribute> attrs_;
|
std::vector<InlineAttribute<string_type, string_adaptor> > attrs_;
|
||||||
}; // class InlineElement
|
}; // class InlineElement
|
||||||
|
|
||||||
} // namespace XSLT
|
} // namespace XSLT
|
||||||
|
|
|
@ -126,7 +126,7 @@ private:
|
||||||
|
|
||||||
Template* lreStylesheet = new Template(context_.xpath_match("/"), "", "", "", context_.precedence());
|
Template* lreStylesheet = new Template(context_.xpath_match("/"), "", "", "", context_.precedence());
|
||||||
context_.push(lreStylesheet,
|
context_.push(lreStylesheet,
|
||||||
new LREStylesheetHandler(context_, lreStylesheet),
|
new LREStylesheetHandler<string_type, string_adaptor>(context_, lreStylesheet),
|
||||||
namespaceURI,
|
namespaceURI,
|
||||||
localName,
|
localName,
|
||||||
qName,
|
qName,
|
||||||
|
|
Loading…
Add table
Reference in a new issue