我开始处理一个项目,我接收XML格式的数据,必须将其翻译成代表要执行的python的文本文件。
我遇到了这个:
并想知道XSLT专家对此有何看法。任何反馈都将非常感激。非常感谢提前。
答案 0 :(得分:1)
完全可以通过XSLT生成python脚本。
text
是xsl:output
您可以在样式表中使用它,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:text>#!/usr/bin/env python
</xsl:text>
<xsl:text># This program is a "Hello World" example
</xsl:text>
<xsl:text>print 'Hello world!'</xsl:text>
</xsl:template>
</xsl:stylesheet>
上面的样式表生成以下Python脚本
#!/usr/bin/env python
# This program is a "Hello World" example
print 'Hello world!'