Use XSLT file to open JDiveLog logs

Open JDiveLog files by translating them to subsurface format using XSLT.
These files are identified by the name of the first element (JDiveLog)
and transform is applied to only these.

The XSLT feature is compiled in only if libxslt is installed. The
transformation files are installed globally in Linux under
/usr/share/subsurface/xslt. Windows and OSX still need appropriate Makefile
changes and testing.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Miika Turkia 2011-11-05 12:39:17 +02:00 committed by Linus Torvalds
parent 4b735521e2
commit 350462949d
4 changed files with 52 additions and 3 deletions

View file

@ -7,6 +7,9 @@
#include <time.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#ifdef XSLT
#include <libxslt/transform.h>
#endif
#include "dive.h"
#include "uemis.h"
@ -1466,6 +1469,9 @@ void parse_xml_file(const char *filename, GError **error)
set_filename(filename);
reset_all();
dive_start();
#ifdef XSLT
doc = test_xslt_transforms(doc);
#endif
traverse(xmlDocGetRootElement(doc));
dive_end();
xmlFreeDoc(doc);
@ -1476,3 +1482,23 @@ void parse_xml_init(void)
{
LIBXML_TEST_VERSION
}
#ifdef XSLT
xmlDoc *test_xslt_transforms(xmlDoc *doc)
{
xmlDoc *transformed;
xsltStylesheetPtr xslt = NULL;
xmlNode *root_element = xmlDocGetRootElement(doc);
if (strcasecmp(root_element->name, "JDiveLog") == 0) {
xmlSubstituteEntitiesDefault(1);
xslt = xsltParseStylesheetFile(XSLT G_DIR_SEPARATOR_S "jdivelog2subsurface.xslt");
if (xslt == NULL)
return doc;
transformed = xsltApplyStylesheet(xslt, doc, NULL);
xmlFreeDoc(doc);
xsltFreeStylesheet(xslt);
return transformed;
}
return doc;
}
#endif