src/XPathHandler.h
author František Kučera <franta-hg@frantovo.cz>
Wed, 30 Dec 2020 09:58:39 +0100
branchv_0
changeset 4 c58c7f2d4785
parent 3 709abeb5f6d1
child 5 682c378bc4a2
permissions -rw-r--r--
add current relation name: ../relation-name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <string>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <vector>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <codecvt>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <regex>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
1
d6dbd5d50d43 link to libxml++ / libxml2
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    25
#include <libxml++-2.6/libxml++/libxml++.h>
d6dbd5d50d43 link to libxml++ / libxml2
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    26
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/common/type/typedefs.h>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include <relpipe/reader/TypeId.h>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
#include <relpipe/reader/handlers/AttributeMetadata.h>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
#include <relpipe/writer/Factory.h>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
#include <relpipe/cli/RelpipeCLIException.h>
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
#include "Configuration.h"
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    37
#include "XMLNameCodec.h"
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
namespace relpipe {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
namespace tr {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
namespace xpath {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
class XPathHandler : public relpipe::reader::handlers::RelationalReaderStringHandler {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
private:
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    45
	std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // XML is in UTF-8
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	shared_ptr<relpipe::writer::RelationalWriter> relationalWriter;
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	Configuration configuration;
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    48
	RelationConfiguration* currentRelationConfiguration = nullptr;
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	std::vector<relpipe::reader::handlers::AttributeMetadata> currentReaderMetadata;
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	std::vector<relpipe::writer::AttributeMetadata> currentWriterMetadata;
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	size_t currentAttributeIndex = 0;
3
709abeb5f6d1 add current record number: @number
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    52
	size_t currentRecordNumber = 1;
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    53
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    54
1
d6dbd5d50d43 link to libxml++ / libxml2
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    55
	xmlpp::DomParser dom;
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    56
	xmlpp::Element* recordElement = nullptr;
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    57
	relpipe::in::xmltable::XMLNameCodec xmlNameCodec; // TODO: move to a common library
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	void copyInputAttributesToOutput() {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
		for (auto rm : currentReaderMetadata) currentWriterMetadata.push_back({rm.getAttributeName(), relationalWriter->toTypeId(rm.getTypeName())});
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	bool isPrependingInputAttributes() {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		return currentRelationConfiguration->inputAttributePolicy == InputAttributePolicy::Prepend
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
				|| (currentRelationConfiguration->inputAttributePolicy == InputAttributePolicy::Auto && currentRelationConfiguration->outputAttributes.size() == 0);
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
	bool isAppendingInputAttributes() {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
		return currentRelationConfiguration->inputAttributePolicy == InputAttributePolicy::Append;
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
	}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    72
	void resetRecordElement() {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    73
		if (recordElement) dom.get_document()->get_root_node()->remove_child(recordElement);
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    74
		recordElement = dom.get_document()->get_root_node()->add_child("record");
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    75
	}
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    76
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    77
	const Glib::ustring s2x(relpipe::common::type::StringX value) {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    78
		return Glib::ustring(convertor.to_bytes(value));
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    79
	}
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    80
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    81
	const relpipe::common::type::StringX x2s(const Glib::ustring& value) {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    82
		return convertor.from_bytes(value);
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    83
	}
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    84
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    85
	void writeInputAttributes() {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    86
		for (xmlpp::Node* attributeNode : recordElement->get_children()) {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    87
			if (xmlpp::Element * attributeElement = dynamic_cast<xmlpp::Element*> (attributeNode)) {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    88
				auto value = attributeElement->get_child_text()->get_content();
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    89
				relationalWriter->writeAttribute(x2s(value));
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    90
			}
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    91
		}
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    92
	}
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    93
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    94
	void writeOutputAttributes() {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    95
		for (auto oa : currentRelationConfiguration->outputAttributes) {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    96
			auto value = recordElement->eval_to_string(s2x(oa.xpath));
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    97
			relationalWriter->writeAttribute(x2s(value));
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    98
		}
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    99
	}
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   100
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
public:
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
	XPathHandler(shared_ptr<relpipe::writer::RelationalWriter> relationalWriter, Configuration configuration) : relationalWriter(relationalWriter), configuration(configuration) {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   104
	}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   105
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   106
	virtual ~XPathHandler() {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   107
	}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   108
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   109
	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   110
		currentRelationConfiguration = nullptr;
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   111
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   112
		for (int i = 0; i < configuration.relationConfigurations.size(); i++) {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   113
			if (std::regex_match(name, std::wregex(configuration.relationConfigurations[i].relation))) {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
				currentRelationConfiguration = &configuration.relationConfigurations[i];
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   115
				break;
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   116
			}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
		}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   118
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   119
		currentReaderMetadata = attributes;
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   120
		currentWriterMetadata.clear();
3
709abeb5f6d1 add current record number: @number
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
   121
		currentRecordNumber = 1;
709abeb5f6d1 add current record number: @number
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
   122
		recordElement = nullptr;
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   123
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   124
		if (currentRelationConfiguration == nullptr) {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   125
			copyInputAttributesToOutput();
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   126
		} else {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   127
			if (isPrependingInputAttributes()) copyInputAttributesToOutput();
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   128
			for (auto oa : currentRelationConfiguration->outputAttributes) currentWriterMetadata.push_back({oa.name, oa.type});
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   129
			if (isAppendingInputAttributes()) copyInputAttributesToOutput();
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   130
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   131
			dom.get_document()->create_root_node("relpipe-tr-xpath");
4
c58c7f2d4785 add current relation name: ../relation-name
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   132
			dom.get_document()->get_root_node()->add_child("relation-name")->add_child_text(s2x(name));
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   133
			resetRecordElement();
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   134
		}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   135
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   136
		relationalWriter->startRelation(name, currentWriterMetadata, true);
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   137
	}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   138
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   139
	void attribute(const relpipe::common::type::StringX& value) override {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   140
		if (currentRelationConfiguration) {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   141
			relpipe::reader::handlers::AttributeMetadata attributeMetadata = currentReaderMetadata[currentAttributeIndex];
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   142
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   143
			xmlpp::Element* attributeElement = recordElement->add_child(xmlNameCodec.encode(s2x(attributeMetadata.getAttributeName())));
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   144
			attributeElement->set_attribute("name", s2x(attributeMetadata.getAttributeName()));
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   145
			attributeElement->set_attribute("type", s2x(attributeMetadata.getTypeName()));
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   146
			attributeElement->add_child_text(s2x(value));
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   147
3
709abeb5f6d1 add current record number: @number
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
   148
			if (currentAttributeIndex == 0) {
709abeb5f6d1 add current record number: @number
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
   149
				recordElement->set_attribute("number", std::to_string(currentRecordNumber));
709abeb5f6d1 add current record number: @number
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
   150
			}
709abeb5f6d1 add current record number: @number
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
   151
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   152
			currentAttributeIndex++;
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   153
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   154
			if (currentAttributeIndex == currentReaderMetadata.size()) {
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   155
				if (currentRelationConfiguration->where.empty() || recordElement->eval_to_boolean(s2x(currentRelationConfiguration->where))) {
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   156
					if (isPrependingInputAttributes()) writeInputAttributes();
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   157
					writeOutputAttributes();
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   158
					if (isAppendingInputAttributes()) writeInputAttributes();
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   159
				}
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   160
2
426054465916 build DOM, filter records and evaluate XPath expressions for additional output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   161
				resetRecordElement();
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   162
				currentAttributeIndex = 0;
3
709abeb5f6d1 add current record number: @number
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
   163
				currentRecordNumber++;
0
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   164
			}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   165
		} else {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   166
			relationalWriter->writeAttribute(value);
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   167
		}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   168
	}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   169
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   170
	void endOfPipe() {
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   171
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   172
	}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   173
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   174
};
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   175
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   176
}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   177
}
73e60c77be23 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   178
}