Re: [xslt] Query for multiple substring-after (before) calls
- From: Rahul <rsharma netd com>
- To: veillard redhat com, The Gnome XSLT library mailing-list <xslt gnome org>
- Cc:
- Subject: Re: [xslt] Query for multiple substring-after (before) calls
- Date: Wed, 03 May 2006 14:24:32 +0530
Daniel,
I use following code to transform my stylesheets:
#include "libxml/tree.h"
#include "libxslt/xsltInternals.h"
#include "libxslt/transform.h"
#include "libxslt/xsltutils.h"
#include "libxslt/xslt.h"
#include "libxslt/documents.h"
#include "libxslt/attributes.h"
#include "libxslt/imports.h"
#include "libxslt/variables.h"
#include "string.h"
#include "stdio.h"
void xmlTocli (char * postedXml, char * xslfilename){
FILE* clioutPtr;
xmlDoc *doc= NULL;
xmlNode *root_element ;
printf("\n######### opening xml file ###########\n");
clioutPtr = fopen("transform.xml", "w+");
if (!clioutPtr) {
fprintf(stderr, "Cannot open target file: ");
perror("");
exit(1);
}
xmlInitParser();
/*parse the file and get the DOM */
doc = xmlReadFile(postedXml, NULL, 0);
if (doc == NULL) {
printf("error: could not parse file %s\n", postedXml);
}
root_element = xmlDocGetRootElement(doc);
xsltStylesheetPtr xsl =xsltParseStylesheetFile(xslfilename);
xmlDocPtr result = xsltApplyStylesheet(xsl, doc, NULL);
xsltSaveResultToFile(clioutPtr, result,xsl);
xmlFreeDoc(doc);
xmlFreeDoc(result);
xsltFreeStylesheet(xsl);
fclose(clioutPtr);
printf("\n##############Saved transform.xml ############\n");
}
/* main to test the function */
int main(int argc, char **argv)
{
char *myXMLfile;
myXMLfile = argv[1];
exsltRegisterAll();
xmlTocli(myXMLfile, "xslfile.xsl");
return 0;
}
My Input XML is:
<?xml version="1.0"?>
<precli>
<param>
<param-parent>rahul anil pandey tiwari sharma
babu</param-parent>
</param>
</precli>
My XSLT File is:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings" exclude-result-prefixes="str">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<crypto>
<ike>
<key>
<xsl:for-each
select="/precli/param/param-parent">
<xsl:element
name="{normalize-space(substring-before(substring-after(.,'pandey'),' '))}"/>
<!-- <xsl:element
name="{normalize-space(substring-before(.,' '))}"/> -->
</xsl:for-each>
</key>
</ike>
</crypto>
</xsl:template>
</xsl:stylesheet>
Daniel Veillard wrote:
then provide full input informations allowing to reproduce this with
xsltproc, make sure xsltproc behaviour is different than other XSLT processors.
if this is the case then bugzilla thi, thanks.
Daniel
On Wed, May 03, 2006 at 01:47:27PM +0530, Rahul wrote:
Daniel,
I used that too, i.e.   it gives me the same error. Any other
alternative?
<?xml version="1.0"?>
<precli>
<param>
<param-parent>rahul anil pandey tiwari sharma babu</param-parent>
</param>
</precli>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings" exclude-result-prefixes="str">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<crypto>
<ike>
<key>
<xsl:for-each select="/precli/param/param-parent">
<xsl:element name="{normalize-space(substring-before(substring-after(.,'pandey'),' '))}"/>
<!-- <xsl:element name="{normalize-space(substring-before(.,' '))}"/> -->
</xsl:for-each>
</key>
</ike>
</crypto>
</xsl:template>
</xsl:stylesheet>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]