Re: [xslt] Parse stylesheet from a string (in memory) instead of from a file?
- From: "Bloomquist, Leif" <Leif.Bloomquist@mda.space>
- To: Christian Ceelen <christian ceelen gmail com>, "The Gnome XSLT library mailing-list" <xslt gnome org>
- Subject: Re: [xslt] Parse stylesheet from a string (in memory) instead of from a file?
- Date: Thu, 18 Nov 2021 18:34:09 +0000
Hi Christian,
I had to solve this once before. My solution had then several step:
- use xmlReadMemory from libxml2 to read the XML from memory. this creates an xmlDocPtr
- use xmlDocGetRootElement to get the root xmlNodePtr
- use xsltParseStylesheetDoc from libxslt to create the xsltStylesheetPtr
- use xsltApplyStylesheet with the the stylesheet and an xmlDocPtr to convert.
Thank you for the reply! My colleague actually found a post from 2002 with a slightly simpler solution:
https://mail.gnome.org/archives/xslt/2002-January/msg00080.html
So this reduces the solution to two steps (although there should also be an intermediate check that temp
isn't NULL)
xmlDocPtr temp = xmlParseMemory(mystring, (int)strlen(mystring));
xsltStylesheetPtr xsl = xsltParseStylesheetDoc(temp);
From there I can use xsltApplyStylesheet as before, and this approach works perfectly for my use case.
Cheers
-Leif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]