Added several more variables tests, related the namespace prefixes

fixed internal qname resolution - 2.4 says unprefixed names are not in the default namespace
fixed xsl:element - unprefixed names, when no namespace uri is supplied are in teh default namespace
This commit is contained in:
jez 2008-08-05 22:03:33 +01:00
parent 72e8decc76
commit b559feb7be
14 changed files with 114 additions and 20 deletions

View file

@ -38,7 +38,7 @@ public:
std::pair<std::string, std::string> mode; std::pair<std::string, std::string> mode;
if(attrs["mode"] != "") if(attrs["mode"] != "")
mode = context_.processQName(attrs["mode"]); mode = context_.processInternalQName(attrs["mode"]);
applyTemplates_ = new ApplyTemplates(xpath, mode); applyTemplates_ = new ApplyTemplates(xpath, mode);
return; return;

View file

@ -30,7 +30,7 @@ public:
std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules); std::map<std::string, std::string> attrs = gatherAttributes(qName, atts, rules);
std::pair<std::string, std::string> name = context_.processQName(attrs["name"]); std::pair<std::string, std::string> name = context_.processInternalQName(attrs["name"]);
callTemplate_ = new CallTemplate(name); callTemplate_ = new CallTemplate(name);
return; return;

View file

@ -55,11 +55,11 @@ protected:
std::pair<std::string, std::string> name; std::pair<std::string, std::string> name;
if(atts.getValue("name") != "") if(atts.getValue("name") != "")
name = context().processQName(atts.getValue("name")); name = context().processInternalQName(atts.getValue("name"));
std::pair<std::string, std::string> mode; std::pair<std::string, std::string> mode;
if(atts.getValue("mode") != "") if(atts.getValue("mode") != "")
mode = context().processQName(atts.getValue("mode")); mode = context().processInternalQName(atts.getValue("mode"));
if(match == "") if(match == "")
return new Template(name, return new Template(name,

View file

@ -41,7 +41,7 @@ protected:
has_select_ = true; has_select_ = true;
} // if ... } // if ...
std::pair<std::string, std::string> name = this->context().processQName(attrs["name"]); std::pair<std::string, std::string> name = this->context().processInternalQName(attrs["name"]);
return new VType(name.first, name.second, xpath); return new VType(name.first, name.second, xpath);
} // createContainer } // createContainer

View file

@ -58,12 +58,15 @@ public:
Arabica::XPath::XPathExpressionPtr<std::string> xpath_attribute_value_template(const std::string& expr) const { return xpath_.compile_attribute_value_template(expr); } Arabica::XPath::XPathExpressionPtr<std::string> xpath_attribute_value_template(const std::string& expr) const { return xpath_.compile_attribute_value_template(expr); }
Stylesheet& stylesheet() const { return stylesheet_; } Stylesheet& stylesheet() const { return stylesheet_; }
std::pair<std::string, std::string> processQName(const std::string& qName) const std::pair<std::string, std::string> processInternalQName(const std::string& qName) const
{ {
if(!Arabica::XML::is_qname(qName)) if(!Arabica::XML::is_qname(qName))
throw SAX::SAXException("Bad name : " + qName); throw SAX::SAXException("Bad name : " + qName);
// 2.4 The default namespace is not used for unprefixed names.
if(qName.find(':') == std::string::npos)
return std::make_pair("", qName);
return parser_.processQName(qName); return parser_.processQName(qName);
} // processQName } // processInternalQName
std::string makeAbsolute(const std::string& href) const std::string makeAbsolute(const std::string& href) const
{ {

View file

@ -34,7 +34,7 @@ public:
virtual void execute(const DOM::Node<std::string>& node, ExecutionContext& context) const virtual void execute(const DOM::Node<std::string>& node, ExecutionContext& context) const
{ {
std::string name = name_->evaluateAsString(node, context.xpathContext()); std::string name = name_->evaluateAsString(node, context.xpathContext());
if(name.empty()) if(!Arabica::XML::is_qname(name))
throw SAX::SAXException("xsl:element name attribute must evaluate to a valid element name"); throw SAX::SAXException("xsl:element name attribute must evaluate to a valid element name");
std::string namesp; std::string namesp;
@ -44,13 +44,10 @@ public:
else else
{ {
QName qn = QName::createQName(name); QName qn = QName::createQName(name);
if(!qn.prefix.empty()) std::map<std::string, std::string>::const_iterator ns = namespaces_.find(qn.prefix);
{ if(ns == namespaces_.end())
std::map<std::string, std::string>::const_iterator ns = namespaces_.find(qn.prefix); throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix);
if(ns == namespaces_.end()) namesp = ns->second;
throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix);
namesp = ns->second;
} // if(!qn.prefix.empty())
} // if ... } // if ...
if(context.sink().start_element(name, namesp)) if(context.sink().start_element(name, namesp))

View file

@ -1,6 +1,8 @@
#ifndef ARABICA_XSLT_QNAME_HPP #ifndef ARABICA_XSLT_QNAME_HPP
#define ARABICA_XSLT_QNAME_HPP #define ARABICA_XSLT_QNAME_HPP
#include <XML/strings.hpp>
namespace Arabica namespace Arabica
{ {
namespace XSLT namespace XSLT
@ -14,6 +16,9 @@ struct QName
static QName createQName(const std::string& qName) static QName createQName(const std::string& qName)
{ {
if(!Arabica::XML::is_qname(qName))
throw SAX::SAXException("Bad name : " + qName);
static char COLON = Arabica::text::Unicode<char>::COLON; static char COLON = Arabica::text::Unicode<char>::COLON;
QName qn; QName qn;
@ -24,11 +29,6 @@ struct QName
{ {
qn.prefix = qName.substr(0, colon); qn.prefix = qName.substr(0, colon);
qn.localName = qName.substr(colon+1); qn.localName = qName.substr(colon+1);
if((qn.prefix.length() == 0) ||
(qn.localName.length() == 0) ||
(qn.localName.find(COLON) != std::string::npos))
throw SAX::SAXException("Bad qname");
} }
return qn; return qn;

View file

@ -178,5 +178,41 @@
<output-file role="principal">import_precedence2_result.xml</output-file> <output-file role="principal">import_precedence2_result.xml</output-file>
</scenario> </scenario>
</test-case> </test-case>
<test-case id="variables07">
<file-path>variables</file-path>
<purpose>namespace</purpose>
<scenario operation="standard">
<input-file role="principal-data">foo.xml</input-file>
<input-file role="principal-stylesheet">namespace.xsl</input-file>
<output-file role="principal">namespace_result.xml</output-file>
</scenario>
</test-case>
<test-case id="variables08">
<file-path>variables</file-path>
<purpose>namespace</purpose>
<scenario operation="standard">
<input-file role="principal-data">foo.xml</input-file>
<input-file role="principal-stylesheet">namespace2.xsl</input-file>
<output-file role="principal">namespace_result.xml</output-file>
</scenario>
</test-case>
<test-case id="variables09">
<file-path>variables</file-path>
<purpose>namespace</purpose>
<scenario operation="standard">
<input-file role="principal-data">foo.xml</input-file>
<input-file role="principal-stylesheet">namespace3.xsl</input-file>
<output-file role="principal">namespace_result.xml</output-file>
</scenario>
</test-case>
<test-case id="variables10">
<file-path>variables</file-path>
<purpose>namespace</purpose>
<scenario operation="standard">
<input-file role="principal-data">foo.xml</input-file>
<input-file role="principal-stylesheet">namespace4.xsl</input-file>
<output-file role="principal">namespace4_result.xml</output-file>
</scenario>
</test-case>
</test-catalog> </test-catalog>
</test-suite> </test-suite>

View file

@ -0,0 +1 @@
<e1 xmlns="urn:foo">var(foo)</e1>

View file

@ -0,0 +1 @@
<e1>var(foo)</e1>

View file

@ -0,0 +1,13 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
<xsl:element name="e1"><xsl:value-of select="$foo"/></xsl:element>
</xsl:template>
<xsl:variable name="foo" select="'var(foo)'"/>
</xsl:stylesheet>

View file

@ -0,0 +1,14 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="urn:foo"
>
<xsl:template match="/">
<xsl:element name="e1"><xsl:value-of select="$foo:foo"/></xsl:element>
</xsl:template>
<xsl:variable name="foo:foo" select="'var(foo)'"/>
</xsl:stylesheet>

View file

@ -0,0 +1,15 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="urn:foo"
xmlns:bar="urn:foo"
>
<xsl:template match="/">
<xsl:element name="e1"><xsl:value-of select="$foo:foo"/></xsl:element>
</xsl:template>
<xsl:variable name="bar:foo" select="'var(foo)'"/>
</xsl:stylesheet>

View file

@ -0,0 +1,14 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="urn:foo"
>
<xsl:template match="/">
<xsl:element name="e1"><xsl:value-of select="$foo"/></xsl:element>
</xsl:template>
<xsl:variable name="foo" select="'var(foo)'"/>
</xsl:stylesheet>