Microsoft Word.docx文件的xsl转换
docx-xslt的Python项目详细描述
docx xslt是一个python库,用于为 没有XML或xslt编码的Microsoft Word.docx文件。
模块使用word元文本,该文本已用特定的 名为xsl的字符模板,添加xsl代码并应用xsl 与XML上下文的转换。
元文本具有以下语法:
<meta text> ::= <command list> <command list> ::= <command expr> | <command list> <command expr> ::= ‘xsl’ ‘:’ <context expr> <xsl command expr> <xsl option expr> <context expr> ::= ‘:’ <context type> | <context type> ::= ‘body’ | ‘p0’ | ‘p’ | ‘r’ | ‘t’ | ‘tbl’ | ‘tr’ | ‘tc’ <xsl command expr> ::= <meta command> | <xsl command> <meta command> ::= ‘meta’ <meta sub command> <meta sub command> ::= ‘up’ | ‘prev’ | ‘next’ | ‘cloneprev’ | ‘clonenext’ | ‘delete’ <xsl command> ::= ‘for-each’ | ‘choose’ | ‘when’ | ‘otherwise’ | ‘if’ | ‘sort’ | ‘value-of’ | ‘text’ <xsl option expr> ::= <text> | <xsl option name> ‘=’ <xsl option value> <text> ::= … <xsl option name> ::= ‘select’ | ‘test’ <xsl option value> ::= xpath expr
要插入产品名称列表,只需添加 xsl:for each select=.//products/*xsl:t:value of select=名称和格式 带有xsl模板的文本。
~~~~{.python} 从lxml导入etree 从docxxslt导入docxxslt模板
context=etree.parse(“products.xml”) 模板=docxxslttemplate(文件名) template.save(context=context) ~~~~
安装
~~~~{.bash} pip安装docx xslt ~~~~