diff --git a/tests/rapport.xsl b/tests/rapport.xsl index fac2bf3..d03da58 100644 --- a/tests/rapport.xsl +++ b/tests/rapport.xsl @@ -1,5 +1,5 @@ - + diff --git a/xml/Document.cpp b/xml/Document.cpp index d6abb2a..eefa045 100644 --- a/xml/Document.cpp +++ b/xml/Document.cpp @@ -40,6 +40,10 @@ xml::Content* xml::Document::getRoot() return root; } +string xml::Document::getFilePath() { + return filePath; +} + ostream& xml::Document::toString(ostream& stream) { if (!doctype.empty()) diff --git a/xml/Document.hpp b/xml/Document.hpp index 35cdf68..40026fa 100644 --- a/xml/Document.hpp +++ b/xml/Document.hpp @@ -1,6 +1,5 @@ # ifndef __DOCUMENT_H__ # define __DOCUMENT_H__ - # include "ProcessingInstruction.hpp" # include "Content.hpp" # include "Comment.hpp" @@ -26,7 +25,9 @@ namespace xml { private: std::string rootName; std::string doctype; - + + std::string filePath; + ProcessingInstruction *xmlProlog; Content *root; std::list comments; @@ -48,6 +49,15 @@ namespace xml { rootName = _d.first; doctype = _d.second; } + + /** + * Mutateur : Définit le chemin vers le fichier à l'origine de ce document. + * @param _d Chemin vers le fichier utilisé. + */ + void setFilePath(const char* _d) + { + filePath = std::string(_d); + } /** * Mutateur : Définit le prologue xml. @@ -72,6 +82,12 @@ namespace xml { * @returns L'élément racine. */ Content* getRoot(); + + /** + * Accesseur : renvoie le chemin vers le fichier à l'origine de ce document. + * @returns L'élément racine. + */ + std::string getFilePath(); /** * Destructeur de l'objet. @@ -81,7 +97,7 @@ namespace xml { /** * Constructeur par défaut de l'objet, initialise les variables aux valeurs par défaut. */ - Document() : doctype(""), xmlProlog(0), root(0) { /* empty */ } + Document() : doctype(""), xmlProlog(0), root(0), filePath() { /* empty */ } /** * Affiche le contenu du document (ie l'ensemble de son arboresence) dans le flux passé. diff --git a/xml/xml.y b/xml/xml.y index c48ecbb..abca677 100644 --- a/xml/xml.y +++ b/xml/xml.y @@ -266,9 +266,13 @@ xml::Document* parseXML(const char* file) fprintf(stderr, "Parse ended with %d error(s)\n", err); document = NULL; } + fclose(xmlin); xmllex_destroy(); } + if (document != NULL) { + document->setFilePath(file); + } return document; } diff --git a/xsl/Test.cpp b/xsl/Test.cpp index fd78fdb..d46df6b 100644 --- a/xsl/Test.cpp +++ b/xsl/Test.cpp @@ -71,8 +71,8 @@ struct XSLProcessTest_NoHTMLDTD : public TestCase xml::Document* document = NULL; dtd::Document* docDtd; - docDtd = parseDTD("tests/html.dtd"); - document = parseXML("tests/testNoHTMLDTD.xsl"); + docDtd = parseDTD("./tests/html.dtd"); + document = parseXML("./tests/testNoHTMLDTD.xsl"); XSLProcessor xslProcessor = XSLProcessor(); try{ xslProcessor.setXslDTD(docDtd); @@ -101,7 +101,6 @@ struct XSLProcessTest_InvalidHTMLDTD : public TestCase docXml = parseXML("./tests/testHtmlDtdInvalid.xsl"); docDtd = parseDTD("./tests/xsl.dtd"); - try { proc.setXslDTD(docDtd); proc.processXslFile(docXml); diff --git a/xsl/XSLProcessor.cpp b/xsl/XSLProcessor.cpp index a84f216..19bb6b3 100644 --- a/xsl/XSLProcessor.cpp +++ b/xsl/XSLProcessor.cpp @@ -1,4 +1,3 @@ - /** * @file XSLProcessor.cpp * @brief Implementation - XSL processing functions @@ -8,8 +7,6 @@ * @author Daniel BAUDRY & Benjamin Bill PLANCHE (Aldream) */ -#include - #include "XSLProcessor.hpp" #include "../xml/basics.h" @@ -75,10 +72,17 @@ void xsl::XSLProcessor::processXslFile(xml::Document* newXslDoc) throw (string) string attrXMLNS = rootXSL->getAttributeValue("xmlns:xsl"); if (attrXMLNS.empty()) { throw(ERROR_NO_XMLNS); - } + } + // --------- Building a full path, by prepending the path to the folder of the XSL file to the path to the HTML DTD file (without this, if the program is running in a different folder than the XSL file, it won't be able to find the HTML DTD with the relative path of the XSL) + string xslPath = newXslDoc->getFilePath(); + string fullHtmlDtdPath = attrXMLNS; + if (attrXMLNS[0] != '/') { + string xslFolder = xslPath.substr(0, xslPath.find_last_of("/\\")); + fullHtmlDtdPath = xslFolder + "/" + attrXMLNS; + } // --------- Opening, validating ant getting the structure of the HTML DTD file : - dtd::Document * htmlDTDdoc = parseDTD(attrXMLNS.c_str()); + dtd::Document * htmlDTDdoc = parseDTD(fullHtmlDtdPath.c_str()); if (htmlDTDdoc == NULL) { throw(ERROR_INVALID_HTML_DTD); } diff --git a/xsl/tests/rapport.xsl b/xsl/tests/rapport.xsl index 42a4cc0..44237af 100644 --- a/xsl/tests/rapport.xsl +++ b/xsl/tests/rapport.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/rapportInvalidXSL.xsl b/xsl/tests/rapportInvalidXSL.xsl index dc16263..df0dbe5 100644 --- a/xsl/tests/rapportInvalidXSL.xsl +++ b/xsl/tests/rapportInvalidXSL.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/rapportSemanticHTML.xsl b/xsl/tests/rapportSemanticHTML.xsl index d862166..fd14b67 100644 --- a/xsl/tests/rapportSemanticHTML.xsl +++ b/xsl/tests/rapportSemanticHTML.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/rapportSemanticXSL.xsl b/xsl/tests/rapportSemanticXSL.xsl index 549433a..0d5a272 100644 --- a/xsl/tests/rapportSemanticXSL.xsl +++ b/xsl/tests/rapportSemanticXSL.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/testApplyTemplates.xsl b/xsl/tests/testApplyTemplates.xsl index 78328e7..ce033db 100644 --- a/xsl/tests/testApplyTemplates.xsl +++ b/xsl/tests/testApplyTemplates.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/testAttribute.xsl b/xsl/tests/testAttribute.xsl index bdf814e..3858860 100644 --- a/xsl/tests/testAttribute.xsl +++ b/xsl/tests/testAttribute.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/testComplex.xsl b/xsl/tests/testComplex.xsl index 9e3a1b8..1850cc6 100644 --- a/xsl/tests/testComplex.xsl +++ b/xsl/tests/testComplex.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/testHtmlDtdInvalid.xsl b/xsl/tests/testHtmlDtdInvalid.xsl index ac3c2f6..a0fde89 100644 --- a/xsl/tests/testHtmlDtdInvalid.xsl +++ b/xsl/tests/testHtmlDtdInvalid.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/testNoRoot.xsl b/xsl/tests/testNoRoot.xsl index d434341..e0d9d7e 100644 --- a/xsl/tests/testNoRoot.xsl +++ b/xsl/tests/testNoRoot.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/testSimple.xsl b/xsl/tests/testSimple.xsl index 030afb2..6b34f4c 100644 --- a/xsl/tests/testSimple.xsl +++ b/xsl/tests/testSimple.xsl @@ -1,5 +1,5 @@ - + diff --git a/xsl/tests/testValueOf.xsl b/xsl/tests/testValueOf.xsl index dbe1a16..3770e61 100644 --- a/xsl/tests/testValueOf.xsl +++ b/xsl/tests/testValueOf.xsl @@ -1,5 +1,5 @@ - +