How to convert XML to something else using xslt stylesheet?

How to convert XML to another using xslt stylesheet?

In C ++ C # PHP or ActionScript?

For example, I have html2wiki xslt stylesheet. I want to send my XML to my program (in this case, an HTML file) and return the file (in this case, Wiki selects text)

So, how to translate one text file to another text file using the XSLT stylesheet in any language?

+1
source share
7 answers

pseudo code:

Load SOURCE file as XML
Load STYLESHEET file as XML
Apply STYLESHEET to SOURCE, generating RESULT
Write RESULT out to file as XML
+2
source

In Python, libxml and libxslt are my personal choice for this kind of function.


(Edit) libxml libxslt:

#!/usr/bin/python

import sys
import libxml2
import libxslt


def getXSLT(xsl_filename):
    # parse the stylesheet xml file into doc object
    styledoc = libxml2.parseFile(xsl_filename)

    # process the doc object as xslt
    style = libxslt.parseStylesheetDoc(styledoc)

    return style


if __name__ == '__main__':
    style = getXSLT("stylesheet.xsl")
    doc = libxml2.parseFile("data.xml")
    result = style.applyStylesheet(doc, None)

    print result
+4

.NET . ++ Xalan-++. Xalan-++ , .

+1
+1

W3Schools XSLT.

http://www.w3schools.com/xsl/

Good luck

+1
source

The correct library in Python is now lxml. See this answer in StackOverflow. This is a similar syntax and you will have no problem installing it.

0
source

All Articles