How to convert XML to something else using xslt st

2020-03-26 12:57发布

How to convert XML to something else using xslt stylesheet?

In C++ C# PHP or ActionScript?

For example I have this html2wiki xslt stylesheet I want to send to my programm my XML (in this case HTML file ) and get back a file (in this case Wiki mark up text )

So How to translate one text file into another text file using XSLT stylesheet in any language?

7条回答
2楼-- · 2020-03-26 13:34

W3Schools has my favorite XSLT tutorial ..

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

Good luck!

查看更多
迷人小祖宗
3楼-- · 2020-03-26 13:37

In Python, libxml and libxslt are my personal choices for this kind of functionality.


(Edit) Here is a simple example of performing a transformation using libxml and 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楼-- · 2020-03-26 13:46

In .NET, you may want to look at this article. In C++, you can use Xalan-C++. Xalan-C++ even has some handy examples of how to use it.

查看更多
我命由我不由天
5楼-- · 2020-03-26 13:47

The correct library in Python now is lxml. Please see this answer on StackOverflow. It is similar syntax, and you wont have issues in installing it.

查看更多
可以哭但决不认输i
6楼-- · 2020-03-26 13:50

in PHP take a look at this

DomXsltStylesheet->process
and also read the last note at the bottom which has a working example ...

查看更多
来,给爷笑一个
7楼-- · 2020-03-26 13:55

Pseudocode:

Load SOURCE file as XML
Load STYLESHEET file as XML
Apply STYLESHEET to SOURCE, generating RESULT
Write RESULT out to file as XML
查看更多
登录 后发表回答