[xslt] [NOVICE] Differences processing Stylesheet from memory vs from file



I have just started using libxslt & am having some problems working out the difference between creating DOms in memory and parsing the XML from files.

I wrote this code

char *applyStyle(xmlDocPtr style, xmlDocPtr doc) {
  char *out;
  int len;
  xmlDocPtr tmp;
  xmlDocPtr htmlDoc;
  xmlSubstituteEntitiesDefault(1);
  xmlLoadExtDtdDefaultValue = 1;
  it = xsltParseStylesheetDoc(style);
  htmlDoc = xsltApplyStylesheet(it,doc,NULL);
  if (it != NULL && htmlDoc != NULL) {
    res = xsltSaveResultToString(&out,&len,htmlDoc,it);
    return out;
  } else {
    return NULL;
  }
}

Both 'style & 'doc' are created as in-memory DOMs,  & I have checked them for correctness by saving to file & examining the files. I cannot get the result I expect - in this code, 'it' always ends up as NULL.

If I change the code to save & re-parse the same DOMs

char *applyStyle(xmlDocPtr style, xmlDocPtr doc) {
  char *out;
  int len;
  int res;
  xsltStylesheetPtr it = NULL;
  xmlDocPtr tmp;
  xmlDocPtr htmlDoc;
  xmlSubstituteEntitiesDefault(1);
  xmlLoadExtDtdDefaultValue = 1;
  xmlSaveFormatFile("c:/temp/doc.xml",doc,1);
  tmp = xmlParseFile("c:/temp/doc.xml");
  xmlSaveFormatFile("c:/temp/style.xsl",style,1);
  it = xsltParseStylesheetFile("c:/temp/style.xsl");
  htmlDoc = xsltApplyStylesheet(it,tmp,NULL);
  if (it != NULL && htmlDoc != NULL) {
    res = xsltSaveResultToString(&out,&len,htmlDoc,it);
    return out;
  } else {
    return NULL;
  }
}

Everything works as expected.

Can anyone explain the difference for me, please.

Thanks in advance,

John N Pocock
===========



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