[xslt] [HELP] Parsing xml and xsl file and applying stylesheet question



This morning I was trying to compile the code I found on the XSLT Mailing List and adapting it to my need.
The compilation of the file is ok, but when I execute it, I receive this warning:
compilation error: element h1
xsltParseStylesheetProcess : document is not a stylesheet
xsltParseStylesheetDoc failed

I'm using Visual Studio 2010, libxml2-2.7.8 and libxslt-1.1.26-win32.
The xml and xsl files are grabbed from "http://www.zvon.org/xxl/XSLTutorial/Books/Output/example1_ch1.html" the first example (XSLT stylesheet 1).

Hope I gave you all the needed information, I'd like to understand what's the problem with my xml and xsl file.

Best Regards.

--
Your time will come
<source>

<title>XSL</title> 
<author>John Smith</author> 

</source>
<xsl:stylesheet version = '1.0' 
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/"> 
     <h1> 
          <xsl:value-of select="//title"/> 
     </h1> 
     <h2> 
          <xsl:value-of select="//author"/> 
     </h2> 
</xsl:template>


</xsl:stylesheet>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../../../../../../opt/include/libxml/xmlmemory.h"
#include "../../../../../../opt/include/libxml/debugXML.h"
#include "../../../../../../opt/include/libxml/HTMLtree.h"
#include "../../../../../../opt/include/libxml/xmlIO.h"
#include "../../../../../../opt/include/libxml/DOCBparser.h"
#include "../../../../../../opt/include/libxml/xinclude.h"
#include "../../../../../../opt/include/libxml/catalog.h"
#include "C:/opt/libxslt/include/libxslt/xslt.h"
#include "C:/opt/libxslt/include/libxslt/xsltInternals.h"
#include "C:/opt/libxslt/include/libxslt/transform.h"
#include "C:/opt/libxslt/include/libxslt/xsltutils.h"

int main(void) {
    xsltStylesheetPtr style_sheet = NULL;
    xmlDocPtr xmlDoc, xsltDoc, resultDoc;

	FILE* output_file = stdout;

	xmlDocPtr input_xml_doc, input_xsl_doc;
	xmlDocPtr transformed_doc;

    xmlLoadExtDtdDefaultValue = 1;
    xmlSubstituteEntitiesDefault(1);

	input_xml_doc = xmlParseFile("C:/Users/Doc/Documents/Visual Studio 2010/Projects/XML-Lib/Debug/test.xml");

	style_sheet = xsltParseStylesheetFile((const xmlChar *)"C:/Users/Doc/Documents/Visual Studio 2010/Projects/XML-Lib/Debug/test.xsl");

	// apply XSL
	transformed_doc = xsltApplyStylesheet(style_sheet, input_xml_doc, NULL);

    xmlDocDump( output_file, input_xml_doc);
    printf("--------\n");
    xmlDocDump( output_file, transformed_doc);
    printf("--------\n");
    if( transformed_doc != NULL && input_xml_doc != NULL ) {
		style_sheet = xsltParseStylesheetDoc( transformed_doc ); //during the debug session this line return the warning
	if (style_sheet != NULL) {
	    resultDoc = xsltApplyStylesheet(style_sheet, input_xml_doc, NULL);
	    if (resultDoc != NULL) {
			xsltSaveResultToFile(stdout, resultDoc, style_sheet);
	    } else {
		printf("xsltApplyStylesheet failed\n");
	    }
	} else {
	    printf("xsltParseStylesheetDoc failed\n");
	}
    } else {
	printf("xmlParseMemory failed\n");
    }
    return(0);
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]