mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-31 19:57:28 +01:00
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:
parent
72e8decc76
commit
b559feb7be
14 changed files with 114 additions and 20 deletions
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
std::pair<std::string, std::string> mode;
|
||||
if(attrs["mode"] != "")
|
||||
mode = context_.processQName(attrs["mode"]);
|
||||
mode = context_.processInternalQName(attrs["mode"]);
|
||||
applyTemplates_ = new ApplyTemplates(xpath, mode);
|
||||
|
||||
return;
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
|
||||
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);
|
||||
return;
|
||||
|
|
|
@ -55,11 +55,11 @@ protected:
|
|||
|
||||
std::pair<std::string, std::string> name;
|
||||
if(atts.getValue("name") != "")
|
||||
name = context().processQName(atts.getValue("name"));
|
||||
name = context().processInternalQName(atts.getValue("name"));
|
||||
|
||||
std::pair<std::string, std::string> mode;
|
||||
if(atts.getValue("mode") != "")
|
||||
mode = context().processQName(atts.getValue("mode"));
|
||||
mode = context().processInternalQName(atts.getValue("mode"));
|
||||
|
||||
if(match == "")
|
||||
return new Template(name,
|
||||
|
|
|
@ -41,7 +41,7 @@ protected:
|
|||
has_select_ = true;
|
||||
} // 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);
|
||||
} // createContainer
|
||||
|
||||
|
|
|
@ -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); }
|
||||
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))
|
||||
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);
|
||||
} // processQName
|
||||
} // processInternalQName
|
||||
|
||||
std::string makeAbsolute(const std::string& href) const
|
||||
{
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
virtual void execute(const DOM::Node<std::string>& node, ExecutionContext& context) const
|
||||
{
|
||||
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");
|
||||
|
||||
std::string namesp;
|
||||
|
@ -44,13 +44,10 @@ public:
|
|||
else
|
||||
{
|
||||
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())
|
||||
throw SAX::SAXException("xsl:element Runtime Error - Undeclared prefix " + qn.prefix);
|
||||
namesp = ns->second;
|
||||
} // if(!qn.prefix.empty())
|
||||
} // if ...
|
||||
|
||||
if(context.sink().start_element(name, namesp))
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef ARABICA_XSLT_QNAME_HPP
|
||||
#define ARABICA_XSLT_QNAME_HPP
|
||||
|
||||
#include <XML/strings.hpp>
|
||||
|
||||
namespace Arabica
|
||||
{
|
||||
namespace XSLT
|
||||
|
@ -14,6 +16,9 @@ struct 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;
|
||||
QName qn;
|
||||
|
||||
|
@ -24,11 +29,6 @@ struct QName
|
|||
{
|
||||
qn.prefix = qName.substr(0, colon);
|
||||
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;
|
||||
|
|
|
@ -178,5 +178,41 @@
|
|||
<output-file role="principal">import_precedence2_result.xml</output-file>
|
||||
</scenario>
|
||||
</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-suite>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<e1 xmlns="urn:foo">var(foo)</e1>
|
|
@ -0,0 +1 @@
|
|||
<e1>var(foo)</e1>
|
13
tests/XSLT/testsuite/TESTS/arabica/variables/namespace.xsl
Normal file
13
tests/XSLT/testsuite/TESTS/arabica/variables/namespace.xsl
Normal 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>
|
14
tests/XSLT/testsuite/TESTS/arabica/variables/namespace2.xsl
Normal file
14
tests/XSLT/testsuite/TESTS/arabica/variables/namespace2.xsl
Normal 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>
|
15
tests/XSLT/testsuite/TESTS/arabica/variables/namespace3.xsl
Normal file
15
tests/XSLT/testsuite/TESTS/arabica/variables/namespace3.xsl
Normal 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>
|
14
tests/XSLT/testsuite/TESTS/arabica/variables/namespace4.xsl
Normal file
14
tests/XSLT/testsuite/TESTS/arabica/variables/namespace4.xsl
Normal 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>
|
Loading…
Add table
Reference in a new issue