For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > November 2006 > XSLT processing









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author XSLT processing
Brian Hancock

2006-11-18, 6:55 pm

Hi,

My Perl script receives data back from a legacy database in the form of an
XML file, which I want to process with an XSL template. I am thinking of
using 'xsltproc' to process the file.

The only way I have used xsltproc is as a commandline , eg

system('xsltproc -o myoutput.xxx mytemplate.xsl myxml.xml')

and then reading the output file, which might either be an xml or a html
document, and printing it to stdout, and then unlinking my temporary xml
input and the output files.

For some scripts, usually in the case of errors , I generate a (very simple)
XML from a string and print that to stdout. I would like also to be able to
apply an XSL template against that, and so I am saving that xml document
string to a temporary file so I can use xsltproc as per above.

I know this is very clumsy. I think perhaps I should be using a pipe, but I
am really at a loss where to start. My two major questions would be,

1. can I apply a transformation against the XSLT and XML but instead of
saving the output to a file, can I retrieve that to a string, and,

2. instead of having my input xml file as a file on disk could it come from
a string representation of my xml document.

Alternatively, should I be approaching this from an entirely different
direction.

Many thanks
Brian






Sean Davis

2006-11-18, 9:55 pm

Brian Hancock wrote:
> Hi,
>
> My Perl script receives data back from a legacy database in the form
> of an XML file, which I want to process with an XSL template. I am
> thinking of using 'xsltproc' to process the file.
>
> The only way I have used xsltproc is as a commandline , eg
>
> system('xsltproc -o myoutput.xxx mytemplate.xsl myxml.xml')
>
> and then reading the output file, which might either be an xml or a
> html document, and printing it to stdout, and then unlinking my
> temporary xml input and the output files.
>
> For some scripts, usually in the case of errors , I generate a (very
> simple) XML from a string and print that to stdout. I would like also
> to be able to apply an XSL template against that, and so I am saving
> that xml document string to a temporary file so I can use xsltproc as
> per above.
>
> I know this is very clumsy. I think perhaps I should be using a pipe,
> but I am really at a loss where to start. My two major questions would
> be,
>
> 1. can I apply a transformation against the XSLT and XML but instead
> of saving the output to a file, can I retrieve that to a string, and,
>
> 2. instead of having my input xml file as a file on disk could it come
> from a string representation of my xml document.
>
> Alternatively, should I be approaching this from an entirely different
> direction.

I think you probably want to think about a different direction
entirely. Start with a google search of XSLT and CGI. You will find a
number of articles. No temporary files or or system() calls should be
necessary. Also, a search of CPAN for XSLT will likely turn up many
interesting modules.

Sean
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com