set base URI correctly on included stylesheets, while also respecting xml:base (like Saxon, but not like msxml and xalan, ner ner)

This commit is contained in:
jez 2007-08-24 12:37:32 +00:00
parent cb35ff15c4
commit 320344dfec
3 changed files with 25 additions and 3 deletions

View file

@ -149,14 +149,18 @@ private:
check_for_loops(current_includes_, href);
current_includes_.push_back(href);
std::string prev = context_->setBase(href);
SAX::InputSource source(href);
SAX::XMLReader<std::string> include_parser;
SAX::CatchErrorHandler<std::string> errorHandler;
include_parser.setContentHandler(*this);
include_parser.setErrorHandler(errorHandler);
include_parser.parse(source);
context_->setBase(prev);
if(errorHandler.errorsReported())
throw std::runtime_error("Could not import/include stylesheet '" + href + "' - " + errorHandler.errors());

View file

@ -58,6 +58,11 @@ public:
return parser_.makeAbsolute(href);
} // makeAbsolute
std::string setBase(const std::string& href) const
{
return parser_.setBase(href);
} // setBase
void push(ItemContainer* parent,
SAX::DefaultHandler* newHandler,
const std::string& namespaceURI,
@ -84,9 +89,10 @@ public:
return *parentStack_.top();
} // parentContainer
SAX::DefaultHandler& parentHandler() const
SAX::ContentHandler& parentHandler() const
{
return *handlerStack_.top();
parser_.setContentHandler(*handlerStack_.top());
return parser_.contentHandler();
} // parentHandler
std::map<std::string, std::string> inScopeNamespaces() const

View file

@ -20,6 +20,11 @@ public:
{
namespace_tracker_.setContentHandler(handler);
} // setContentHandler
SAX::ContentHandler& contentHandler()
{
return text_coalescer_;
} // contentHandler
void parse(SAX::InputSource& source)
{
@ -46,6 +51,13 @@ public:
return namespace_tracker_.inScopeNamespaces();
} // inScopeNamespaces
std::string setBase(const std::string& loc)
{
std::string current = currentBase();
xmlbase_tracker_.setDocumentLocation(loc);
return current;
} // setBase
std::string currentBase() const
{
return xmlbase_tracker_.currentBase();