src/XPathHandler.h
branchv_0
changeset 5 682c378bc4a2
parent 4 c58c7f2d4785
child 6 e498b3466342
--- a/src/XPathHandler.h	Wed Dec 30 09:58:39 2020 +0100
+++ b/src/XPathHandler.h	Wed Dec 30 10:03:21 2020 +0100
@@ -52,6 +52,7 @@
 	size_t currentRecordNumber = 1;
 
 
+	xmlpp::Node::PrefixNsMap xmlns;
 	xmlpp::DomParser dom;
 	xmlpp::Element* recordElement = nullptr;
 	relpipe::in::xmltable::XMLNameCodec xmlNameCodec; // TODO: move to a common library
@@ -93,7 +94,7 @@
 
 	void writeOutputAttributes() {
 		for (auto oa : currentRelationConfiguration->outputAttributes) {
-			auto value = recordElement->eval_to_string(s2x(oa.xpath));
+			auto value = recordElement->eval_to_string(s2x(oa.xpath), xmlns);
 			relationalWriter->writeAttribute(x2s(value));
 		}
 	}
@@ -101,6 +102,11 @@
 public:
 
 	XPathHandler(shared_ptr<relpipe::writer::RelationalWriter> relationalWriter, Configuration configuration) : relationalWriter(relationalWriter), configuration(configuration) {
+		for (int i = 0; i < configuration.namespaceMappings.size(); i++) {
+			std::string prefix = convertor.to_bytes(configuration.namespaceMappings[i]);
+			std::string uri = convertor.to_bytes(configuration.namespaceMappings[++i]);
+			xmlns[prefix] = uri;
+		}
 	}
 
 	virtual ~XPathHandler() {
@@ -152,7 +158,7 @@
 			currentAttributeIndex++;
 
 			if (currentAttributeIndex == currentReaderMetadata.size()) {
-				if (currentRelationConfiguration->where.empty() || recordElement->eval_to_boolean(s2x(currentRelationConfiguration->where))) {
+				if (currentRelationConfiguration->where.empty() || recordElement->eval_to_boolean(s2x(currentRelationConfiguration->where), xmlns)) {
 					if (isPrependingInputAttributes()) writeInputAttributes();
 					writeOutputAttributes();
 					if (isAppendingInputAttributes()) writeInputAttributes();