mirror of
https://github.com/jezhiggins/arabica
synced 2024-11-17 07:48:50 +01:00
2.3 Literal Result Element as Stylesheet - done
This commit is contained in:
commit
5f7bfb66e0
4 changed files with 74 additions and 25 deletions
|
@ -30,20 +30,20 @@ protected:
|
|||
if(atts.getQName(i).find("xmlns:") == 0)
|
||||
continue;
|
||||
if(atts.getURI(i) == StylesheetConstant::NamespaceURI())
|
||||
continue;
|
||||
continue;
|
||||
if(!context().isRemapped(atts.getURI(i)))
|
||||
inlineAtts.push_back(InlineAttribute(atts.getQName(i),
|
||||
atts.getURI(i),
|
||||
context().xpath_attribute_value_template(atts.getValue(i))));
|
||||
inlineAtts.push_back(InlineAttribute(atts.getQName(i),
|
||||
atts.getURI(i),
|
||||
context().xpath_attribute_value_template(atts.getValue(i))));
|
||||
else
|
||||
{
|
||||
std::pair<std::string, std::string> remap = context().remappedNamespace(atts.getURI(i));
|
||||
if(remap.first.empty() && !remap.second.empty())
|
||||
remap.first = context().autoNamespacePrefix();
|
||||
std::string name = remap.first + ":" + atts.getLocalName(i);
|
||||
inlineAtts.push_back(InlineAttribute(name,
|
||||
remap.second,
|
||||
context().xpath_attribute_value_template(atts.getValue(i))));
|
||||
std::pair<std::string, std::string> remap = context().remappedNamespace(atts.getURI(i));
|
||||
if(remap.first.empty() && !remap.second.empty())
|
||||
remap.first = context().autoNamespacePrefix();
|
||||
std::string name = remap.first + ":" + atts.getLocalName(i);
|
||||
inlineAtts.push_back(InlineAttribute(name,
|
||||
remap.second,
|
||||
context().xpath_attribute_value_template(atts.getValue(i))));
|
||||
} // if ...
|
||||
} // for ...
|
||||
|
||||
|
@ -56,6 +56,28 @@ protected:
|
|||
} // createContainer
|
||||
}; // class InlineElementHandler
|
||||
|
||||
class LREStylesheetHandler : public InlineElementHandler
|
||||
{
|
||||
public:
|
||||
LREStylesheetHandler(CompilationContext& context, Template* lreStylesheet) :
|
||||
InlineElementHandler(context),
|
||||
lreStylesheet_(lreStylesheet)
|
||||
{
|
||||
} // LREStylesheetHandler
|
||||
|
||||
virtual void endElement(const std::string& namespaceURI,
|
||||
const std::string& localName,
|
||||
const std::string& qName)
|
||||
{
|
||||
context().stylesheet().add_template(lreStylesheet_);
|
||||
InlineElementHandler::endElement(namespaceURI, localName, qName);
|
||||
} // endElement
|
||||
|
||||
private:
|
||||
Template* lreStylesheet_;
|
||||
}; // class LREStylesheetHandler
|
||||
|
||||
|
||||
} // namespace XSLT
|
||||
} // namespace Arabica
|
||||
|
||||
|
|
|
@ -23,6 +23,12 @@ protected:
|
|||
{
|
||||
} // ItemContainerHandler
|
||||
|
||||
ItemContainerHandler(CompilationContext& context, container_type* container) :
|
||||
context_(context),
|
||||
container_(container)
|
||||
{
|
||||
} // ItemContainerHandler
|
||||
|
||||
virtual container_type* createContainer(const std::string& namespaceURI,
|
||||
const std::string& localName,
|
||||
const std::string& qName,
|
||||
|
|
|
@ -25,8 +25,7 @@ class StylesheetHandler : public SAX::DefaultHandler<std::string>
|
|||
public:
|
||||
StylesheetHandler(CompilationContext& context) :
|
||||
context_(context),
|
||||
top_(false),
|
||||
foreign_(0)
|
||||
top_(false)
|
||||
{
|
||||
context_.root(*this);
|
||||
includer_.context(context_, this);
|
||||
|
@ -44,7 +43,11 @@ public:
|
|||
{
|
||||
if(top_)
|
||||
{
|
||||
startStylesheet(namespaceURI, localName, qName, atts);
|
||||
top_ = false;
|
||||
if(namespaceURI == StylesheetConstant::NamespaceURI())
|
||||
startStylesheet(namespaceURI, localName, qName, atts);
|
||||
else
|
||||
startLREAsStylesheet(namespaceURI, localName, qName, atts);
|
||||
return;
|
||||
} // if(top_)
|
||||
|
||||
|
@ -60,15 +63,10 @@ public:
|
|||
const std::string& localName,
|
||||
const std::string& qName)
|
||||
{
|
||||
if(foreign_)
|
||||
--foreign_;
|
||||
} // endElement
|
||||
|
||||
virtual void characters(const std::string& ch)
|
||||
{
|
||||
if(foreign_)
|
||||
return;
|
||||
|
||||
for(std::string::const_iterator s = ch.begin(), e = ch.end(); s != e; ++s)
|
||||
if(!Arabica::XML::is_space(*s))
|
||||
throw SAX::SAXException("stylesheet element can not contain character data :'" + ch +"'");
|
||||
|
@ -86,8 +84,6 @@ private:
|
|||
const std::string& qName,
|
||||
const SAX::Attributes<std::string>& atts)
|
||||
{
|
||||
if(namespaceURI != StylesheetConstant::NamespaceURI())
|
||||
throw SAX::SAXException("The source file does not look like a stylesheet.");
|
||||
if(localName != "stylesheet" && localName != "transform")
|
||||
throw SAX::SAXException("Top-level element must be 'stylesheet' or 'transform'.");
|
||||
|
||||
|
@ -101,10 +97,36 @@ private:
|
|||
throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer.");
|
||||
if(!attributes["extension-element-prefixes"].empty())
|
||||
throw SAX::SAXException("Haven't implemented extension-element-prefixes yet");
|
||||
|
||||
top_ = false;
|
||||
} // startStylesheet
|
||||
|
||||
void startLREAsStylesheet(const std::string& namespaceURI,
|
||||
const std::string& localName,
|
||||
const std::string& qName,
|
||||
const SAX::Attributes<std::string>& atts)
|
||||
{
|
||||
std::string version;
|
||||
for(int a = 0; a != atts.getLength(); ++a)
|
||||
if((StylesheetConstant::NamespaceURI() == atts.getURI(a)) &&
|
||||
("version" == atts.getLocalName(a)))
|
||||
{
|
||||
version = atts.getValue(a);
|
||||
break;
|
||||
}
|
||||
|
||||
if(version.empty())
|
||||
throw SAX::SAXException("The source file does not look like a stylesheet.");
|
||||
if(version != StylesheetConstant::Version())
|
||||
throw SAX::SAXException("I'm only a poor version 1.0 XSLT Transformer.");
|
||||
|
||||
Template* lreStylesheet = new Template(context_.xpath_match("/"), "", "", "", context_.precedence());
|
||||
context_.push(lreStylesheet,
|
||||
new LREStylesheetHandler(context_, lreStylesheet),
|
||||
namespaceURI,
|
||||
localName,
|
||||
qName,
|
||||
atts);
|
||||
} // startLREAsStylesheet
|
||||
|
||||
void startXSLTElement(const std::string& namespaceURI,
|
||||
const std::string& localName,
|
||||
const std::string& qName,
|
||||
|
@ -161,7 +183,6 @@ private:
|
|||
SAX::DefaultHandler<std::string>* child_;
|
||||
IncludeHandler includer_;
|
||||
bool top_;
|
||||
unsigned int foreign_;
|
||||
|
||||
static const ChildElement allowedChildren[];
|
||||
}; // class StylesheetHandler
|
||||
|
|
|
@ -1240,7 +1240,7 @@
|
|||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="cl /TC /EP -D USE_EXPAT ..\vs7\ArabicaConfig.S > ..\include\SAX\ArabicaConfig.hpp
"
|
||||
CommandLine="cl /TC /EP -D USE_MSXML ..\vs7\ArabicaConfig.S > ..\include\SAX\ArabicaConfig.hpp
"
|
||||
Outputs="..\include\SAX\ArabicaConfig.hpp"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
|
|
Loading…
Reference in a new issue