Browse Source

Klish can use embedded stylesheets

Serj Kalichev 8 years ago
parent
commit
aa2765eeb1
3 changed files with 26 additions and 2 deletions
  1. 10 0
      clish/shell/shell_libxml2.c
  2. 11 2
      clish/shell/shell_xml.c
  3. 5 0
      clish/shell/xmlapi.h

+ 10 - 0
clish/shell/shell_libxml2.c

@@ -349,6 +349,16 @@ clish_xslt_t *clish_xslt_read(const char *filename)
 	return xsltStylesheet_to_xslt(cur);
 }
 
+clish_xslt_t *clish_xslt_read_embedded(clish_xmldoc_t *xmldoc)
+{
+	xsltStylesheet* cur = NULL;
+	xmlDoc *doc = xmldoc_to_doc(xmldoc);
+
+	cur = xsltLoadStylesheetPI(doc);
+
+	return xsltStylesheet_to_xslt(cur);
+}
+
 void clish_xslt_release(clish_xslt_t *stylesheet)
 {
 	xsltStylesheet* cur = xslt_to_xsltStylesheet(stylesheet);

+ 11 - 2
clish/shell/shell_xml.c

@@ -140,8 +140,14 @@ int clish_shell_load_scheme(clish_shell_t *this, const char *xml_path, const cha
 				if (clish_xmldoc_is_valid(doc)) {
 					clish_xmlnode_t *root;
 #ifdef HAVE_LIB_LIBXSLT
-					if (xslt_path) {
-						clish_xmldoc_t *tmp;
+					clish_xmldoc_t *tmp;
+					/* Use embedded stylesheet if stylesheet
+					 * filename is not specified.
+					 */
+					if (!xslt_path)
+						xslt = clish_xslt_read_embedded(doc);
+
+					if (clish_xslt_is_valid(xslt)) {
 						tmp = clish_xslt_apply(doc, xslt);
 						if (!clish_xmldoc_is_valid(tmp)) {
 							fprintf(stderr, CLISH_XML_ERROR_STR"Can't load XSLT file %s\n", xslt_path);
@@ -151,6 +157,9 @@ int clish_shell_load_scheme(clish_shell_t *this, const char *xml_path, const cha
 							doc = tmp;
 						}
 					}
+
+					if (!xslt_path && clish_xslt_is_valid(xslt))
+						clish_xslt_release(xslt);
 #endif
 					if (!res) {
 						root = clish_xmldoc_get_root(doc);

+ 5 - 0
clish/shell/xmlapi.h

@@ -217,6 +217,11 @@ typedef struct clish_xslt_s clish_xslt_t;
  */
 clish_xslt_t *clish_xslt_read(const char *filename);
 
+/*
+ * Load an embedded XSLT stylesheet from already
+ * loaded XML document.
+ */
+clish_xslt_t *clish_xslt_read_embedded(clish_xmldoc_t *xmldoc);
 
 /* Apply XSLT stylesheet */
 clish_xmldoc_t *clish_xslt_apply(clish_xmldoc_t *xmldoc, clish_xslt_t *stylesheet);