在python中使用xslt转换多个xml文件 [英] Transforming multiple xml files using xslt in python

查看:26
本文介绍了在python中使用xslt转换多个xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在单个 xml 文件上运行的 xslt 脚本,我需要提供一个 python 代码,以便我可以使用该代码运行这个 xslt,并使用一些 python 代码在 xslt 的输出中插入一些东西?是否可以使用python调用外部xslt脚本?

I have a xslt script which run on single xml files,I need to come out with a code of python so that i can run this xslt using that code and insert some things in those output of xslt by using some python code?Is it possible to call a external xslt script using python?

例如

输入目录有一些 xml,xslt 在这些输入 xml 上运行并使用 python 脚本在输出目录中创建文件.

input dir have some xmls ,xslt runs on these input xml and create files in output directory using python script.

推荐答案

是的,这是可能的,参见 如何使用 Python 使用 XSLT 转换 XML,或 文档.

Yes, this is possible, see How to transform XML with XSLT using Python, or the documentation.

关于使用多个 XML 文件,您有多种选择:

With regards to using multiple XML files, you have several options:

  1. 使用参数并将其值设置为要加载的文档 URI,并使用 XSLT 中的 document 函数加载多个输入文档
  2. 如果你只知道位置并且它是一个目录,一些处理器允许你使用`document('dir/with/xml/*.xml)'
  3. 如果失败,您可以创建一个 URIResolver.如何做到这一点取决于您使用的处理器.
  1. Use a parameter and set its value to the document URIs you want to load and use the document function in XSLT to load multiple input documents
  2. If you just know the location and it is a directory, some processors allow you to use `document('dir/with/xml/*.xml)'
  3. If that fails, you can create a URIResolver. How to do that depends on the processor you use.

关于创建多个输出文档的问题,使用 XSLT 1.0(通常与 Python 一起使用)不太容易,但您可以切换到使用 XSLT 2.0 with Python,虽然这需要更多的努力来设置.完成此操作后,您可以使用 xsl:result-document 创建多个结果文档以动态计算位置,如果您愿意的话.

With regard to your question on creating multiple output documents, this is less easy with XSLT 1.0 (which is typically used with Python), but you can switch to using XSLT 2.0 with Python, though this requires a bit more effort to set up. Once you have this going, you can use xsl:result-document to create multiple result documents to dynamically calculated locations, if you so prefer.

这篇关于在python中使用xslt转换多个xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆