|
Hello,
It is possible to get XML output in SPSSOMS structure by the OMS command. By a XSLT stylesheet I can transform the SPSSOMS content to another XML format (separate from SPSS). This is a two-step approach. Now I'm wondering if it is possible to integrate this XSLT transformation as a custom SPSS command with Python. I know that the OMS command can write the output also to an XMLWorkspace. By Python it seems to be possible to evaluate XPath expressions against the content of this XMLWorkspace, but it doesn't seem to exist a method for XSLT transformations. The goal would be to transform the content of the XMLWorkspace according to an XSLT stylesheet. Is this possible and how? Any help is much appreciated. Achim |
|
You can approach this in a few ways. I don't have time to go into details right now, but you can pull the xml into your Python program and then stream it to a Python module that does xslt or write it to a file and call an xslt processor from your Python code.
Alternatively you could use standard Python code to process the xml via SAX or elementtree, but if you prefer xslt code, the first approaches would work better. -Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Joachim Wackerow Sent: Friday, May 04, 2007 4:30 PM To: [hidden email] Subject: [SPSSX-L] XSLT Transformation of XMLWorkspace content possible? Hello, It is possible to get XML output in SPSSOMS structure by the OMS command. By a XSLT stylesheet I can transform the SPSSOMS content to another XML format (separate from SPSS). This is a two-step approach. Now I'm wondering if it is possible to integrate this XSLT transformation as a custom SPSS command with Python. I know that the OMS command can write the output also to an XMLWorkspace. By Python it seems to be possible to evaluate XPath expressions against the content of this XMLWorkspace, but it doesn't seem to exist a method for XSLT transformations. The goal would be to transform the content of the XMLWorkspace according to an XSLT stylesheet. Is this possible and how? Any help is much appreciated. Achim |
|
Thanks for the hints.
I had a short look into the details. The solution would be probably something like the following: - Write OMS output of SPSS command (like display dictionary) to an XML workspace in the memory. - get the content of the XML workspace as string by the function spss.GetXmlUtf16 - transform the XML according to a custom stylesheet into another format with an XSLT processor (interface by Python modules) Details see the untested code below. Achim spss.Submit("get file=study.") spss.Submit("oms /destination format=oxml xmlworkspace='dictionary'.") spss.Submit("display dictionary /variables=all.") spss.Submit("omsend.") Dim XMLasString As String = spss.GetXmlUtf16('dictionary') # transformation, alternative 1 for XALAN # pyana module, for XSLT processor XALAN import Pyana print Pyana.transform2String( source=XMLasString, style=Pyana.URI('custom.xslt') ) # transformation, alternative 2 for Libxslt (Gnome) # module for Libxslt data binding import libxml2 import libxslt styledoc = libxml2.parseFile("custom.xslt") style = libxslt.parseStylesheetDoc(styledoc) XML = libxml2.parseDoc( XMLasString ) result = style.applyStylesheet(XML, None) style.saveResultToFilename("foo", result, 0) Peck, Jon wrote: > You can approach this in a few ways. I don't have time to go into details right now, but you can pull the xml into your Python program and then stream it to a Python module that does xslt or write it to a file and call an xslt processor from your Python code. > > Alternatively you could use standard Python code to process the xml via SAX or elementtree, but if you prefer xslt code, the first approaches would work better. > > -Jon Peck > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Joachim Wackerow > Sent: Friday, May 04, 2007 4:30 PM > To: [hidden email] > Subject: [SPSSX-L] XSLT Transformation of XMLWorkspace content possible? > > Hello, > > It is possible to get XML output in SPSSOMS structure by the OMS > command. By a XSLT stylesheet I can transform the SPSSOMS content to > another XML format (separate from SPSS). This is a two-step approach. > > Now I'm wondering if it is possible to integrate this XSLT > transformation as a custom SPSS command with Python. I know that the OMS > command can write the output also to an XMLWorkspace. By Python it seems > to be possible to evaluate XPath expressions against the content of this > XMLWorkspace, but it doesn't seem to exist a method for XSLT > transformations. > > The goal would be to transform the content of the XMLWorkspace according > to an XSLT stylesheet. Is this possible and how? > > Any help is much appreciated. > Achim |
| Free forum by Nabble | Edit this page |
