aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--dummy/in.xml7
-rw-r--r--dummy/test.txt8
-rw-r--r--dummy/transform.xsl15
-rw-r--r--src/read_file_command.h8
-rw-r--r--src/read_xml_file_command.h57
-rw-r--r--src/utility.h5
-rw-r--r--test.cc9
8 files changed, 91 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e98ef8a..7aadb81 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,7 @@ project(InputXSLT)
set(
CMAKE_CXX_FLAGS
- "-std=c++11 -W -Wall -Wextra -Winline -pedantic"
+ "-std=c++11 -W -Wall -Wextra -Winline -pedantic -g"
)
include_directories(
diff --git a/dummy/in.xml b/dummy/in.xml
index 7b512bc..6abcacd 100644
--- a/dummy/in.xml
+++ b/dummy/in.xml
@@ -1,7 +1,2 @@
<?xml version="1.0"?>
-<items>
- <item>Test1</item>
- <item>Test2</item>
- <item>Test3</item>
- <item>Test4</item>
-</items>
+<dummy />
diff --git a/dummy/test.txt b/dummy/test.txt
index cd08755..046a6ef 100644
--- a/dummy/test.txt
+++ b/dummy/test.txt
@@ -1 +1,7 @@
-Hello world!
+<?xml version="1.0"?>
+<tester>
+ <eintrag>Hello 1</eintrag>
+ <eintrag>Hello 2</eintrag>
+ <eintrag>Hello 3</eintrag>
+ <eintrag>Hello 4</eintrag>
+</tester>
diff --git a/dummy/transform.xsl b/dummy/transform.xsl
index bd7cbc7..08d005b 100644
--- a/dummy/transform.xsl
+++ b/dummy/transform.xsl
@@ -15,17 +15,18 @@
<head>
</head>
<body>
- <xsl:apply-templates select="items/item" />
+ <div id="raw">
+ <xsl:value-of select="external:read-file('../dummy/test.txt')" />
+ </div>
+ <ul>
+ <xsl:for-each select="external:read-xml-file('../dummy/test.txt')/tester/eintrag">
+ <li><xsl:value-of select="."/></li>
+ </xsl:for-each>
+ </ul>
</body>
</html>
</xsl:template>
-<xsl:template match="items/item">
- <div id="{.}">
- <xsl:value-of select="external:read-file('../dummy/test.txt')" />
- </div>
-</xsl:template>
-
</xsl:stylesheet>
diff --git a/src/read_file_command.h b/src/read_file_command.h
index 094bb3d..837ec04 100644
--- a/src/read_file_command.h
+++ b/src/read_file_command.h
@@ -9,7 +9,7 @@
namespace xalan = xalanc_1_11;
-class FunctionFileRead : public xalan::Function {
+class FunctionReadFile : public xalan::Function {
public:
virtual xalan::XObjectPtr execute(
xalan::XPathExecutionContext& executionContext,
@@ -43,7 +43,7 @@ class FunctionFileRead : public xalan::Function {
);
}
- virtual FunctionFileRead* clone(xalan::MemoryManager& manager) const {
+ virtual FunctionReadFile* clone(xalan::MemoryManager& manager) const {
return xalan::XalanCopyConstruct(manager, *this);
}
@@ -55,7 +55,7 @@ class FunctionFileRead : public xalan::Function {
}
private:
- FunctionFileRead& operator=(const FunctionFileRead&);
- bool operator==(const FunctionFileRead&) const;
+ FunctionReadFile& operator=(const FunctionReadFile&);
+ bool operator==(const FunctionReadFile&) const;
};
diff --git a/src/read_xml_file_command.h b/src/read_xml_file_command.h
new file mode 100644
index 0000000..96b6c5d
--- /dev/null
+++ b/src/read_xml_file_command.h
@@ -0,0 +1,57 @@
+#include <xalanc/Include/PlatformDefinitions.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
+#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+#include <xalanc/XPath/XObjectFactory.hpp>
+#include <xalanc/XPath/Function.hpp>
+#include <xalanc/XPath/XObject.hpp>
+#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
+
+#include "utility.h"
+
+namespace xalan = xalanc_1_11;
+
+class FunctionReadXmlFile : public xalan::Function {
+ public:
+ virtual xalan::XObjectPtr execute(
+ xalan::XPathExecutionContext& executionContext,
+ xalan::XalanNode* context,
+ const xalan::Function::XObjectArgVectorType& args,
+ const xalan::Locator* locator
+ ) const {
+ if ( args.size() != 1 ) {
+ xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
+ executionContext
+ );
+
+ generalError(executionContext, context, locator);
+ }
+
+ if ( this->liaison == nullptr ) {
+ const_cast<FunctionReadXmlFile*>(this)->liaison = new xalan::XercesParserLiaison();
+ }
+
+ xalan::XSLTInputSource file(args[0]->str());
+
+ return executionContext.getXObjectFactory().createNodeSet(
+ liaison->parseXMLStream(file)
+ );
+ }
+
+ virtual FunctionReadXmlFile* clone(xalan::MemoryManager& manager) const {
+ return xalan::XalanCopyConstruct(manager, *this);
+ }
+
+ protected:
+ xalan::XercesParserLiaison* liaison = nullptr;
+
+ const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const {
+ result.assign("The read-file() function expects one argument.");
+
+ return result;
+ }
+
+ private:
+ FunctionReadXmlFile& operator=(const FunctionReadXmlFile&);
+ bool operator==(const FunctionReadXmlFile&) const;
+
+};
diff --git a/src/utility.h b/src/utility.h
index 7050cee..9c88b38 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -1,3 +1,6 @@
+#ifndef UTILITY_H_
+#define UTILITY_H_
+
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
@@ -46,3 +49,5 @@ std::string readFile(const std::string& path) {
return content;
}
}
+
+#endif // UTILITY_H_
diff --git a/test.cc b/test.cc
index 28a2cac..bc6f0b2 100644
--- a/test.cc
+++ b/test.cc
@@ -4,6 +4,7 @@
#include <xalanc/XSLT/XSLTInputSource.hpp>
#include "src/read_file_command.h"
+#include "src/read_xml_file_command.h"
int main() {
xercesc::XMLPlatformUtils::Initialize();
@@ -18,7 +19,13 @@ int main() {
transformer.installExternalFunction(
customNamespace,
xalan::XalanDOMString("read-file"),
- FunctionFileRead()
+ FunctionReadFile()
+ );
+
+ transformer.installExternalFunction(
+ customNamespace,
+ xalan::XalanDOMString("read-xml-file"),
+ FunctionReadXmlFile()
);
xalan::XSLTInputSource input("../dummy/in.xml");