[xslt] Simple sample?
- From: Simon Flannery <simon_flannery yahoo com au>
- To: xslt gnome org
- Subject: [xslt] Simple sample?
- Date: Mon, 4 Dec 2006 19:51:41 -0800 (PST)
Hi,
I have a silly, but important question. I have coded myself a simplest of samples yet it triggers an illlegal operation (or some other error). I'm using winXP SP2 w/ 1GB RAM etc... and MS VC++ 6.0 and here was my source code. While it compiles just fine, it crashes when I run it.
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/HTMLtree.h>
#include <libxml/xmlIO.h>
#include <libxml/DOCBparser.h>
#include <libxml/xinclude.h>
#include <libxml/catalog.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
extern int xmlLoadExtDtdDefaultValue;
int main()
{
const char* params[16 + 1];
size_t nbparams = 0;
params[nbparams] = NULL;
xmlSubstituteEntitiesDefault(1);
xmlLoadExtDtdDefaultValue = 1;
xsltStylesheetPtr cur = xsltParseStylesheetFile((const xmlChar*) "employees.xsl");
xmlDocPtr doc = xmlParseFile("employees.xml");
xmlDocPtr res = xsltApplyStylesheet(cur, doc, params);
// FILE* p = fopen("out.html", "w");
xsltSaveResultToFile(stdout, res, cur); // <<<<<I think it crashes here!?
// fclose(p);
xsltFreeStylesheet(cur);
xmlFreeDoc(res);
xmlFreeDoc(doc);
xsltCleanupGlobals();
xmlCleanupParser();
return 0;
}
I don't think my employee.xsl/xml source files are to blame, here they are too:
<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<!-- Match the root node -->
<xsl:template match="/">
<html>
<body bgcolor="c0c0c0" text="000000">
<table cellspacing="0" cellpadding="0" border="1" width="100%">
<tr bgcolor="ffffff">
<th width="20%">Department</th>
<th width="10%">ID</th>
<th width="20%">Title</th>
<th width="50%">Name</th>
</tr>
<xsl:apply-templates select="employees/employee">
<xsl:sort select="department" order="ascending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<!-- Match each employee -->
<xsl:template match="employees/employee">
<tr>
<xsl:choose>
<xsl:when test="position() mod 2 = 1">
<xsl:attribute name="bgcolor">c0c0c0</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="bgcolor">cccccc</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<td>
<xsl:value-of select="department" />
</td>
<td>
<xsl:value-of select="department/@id" />
</td>
<td>
<xsl:value-of select="title" />
</td>
<td><xsl:value-of select="family-name" />, <xsl:value-of select="first-name" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
and
<?xml version="1.0" encoding="utf-8" ?>
<employees>
<employee>
<id>101</id>
<first-name>John</first-name>
<family-name>Coake</family-name>
<title>President</title>
<date-started>1997-11-12</date-started>
<salary>324021</salary>
<department id="ADM">Administration</department>
<rating>8</rating>
</employee>
...
</employees>
I'm hoping I've just made a silly mistake and someone here can point it out to me.
Thanks in advance,
Simon
Send instant messages to your online friends http://au.messenger.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]