获取有关尝试从 Python 代码将参数传递到 XSLT 文件的"xsltCompilePattern"



transform.xslt:

<xsl:transform version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:param name="tag"/>
<xsl:param name="uniqueID"/>
<xsl:param name="uniqueIDValue"/>
<xsl:param name="attributeToBeAdded"/>
<xsl:param name="attributeValue"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="{ $tag }[@{ $uniqueID }={ $uniqueIDValue }]">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:attribute name="{$attributeToBeAdded}">{$attributeValue}</xsl:attribute>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:transform>

Python代码:

xml = ET.parse('ABC.xml')
xslt = ET.parse('transform.xslt')
transform = ET.XSLT(xslt)
newdom = xslt(xml, tag=ET.XSLT.strparam("wire"),uniqueID=ET.XSLT.strparam("name"),uniqueIDValue=ET.XSLT.strparam("ABC"),attributeToBeAdded=ET.XSLT.strparam("Fr"),attributeValue=ET.XSLT.strparam("351"))

在运行python代码将参数传递到xslt文件时,我得到以下错误

XSLTParseError:xsltCompilePattern:未能编译"{$tag}[@{$uniqueID}={$uniqueIDValue}]">

我很确定我犯了一些语法错误,需要正确的语法帮助。。谢谢

目前还不清楚您的期望,通常的Python XSLT支持是基于支持XSLT1的libxslt,所以我不明白您为什么在XSLT2.0和3.0版本中使用这些标签。此外,在任何版本的XSLT中,无论您以何种方式设置参数,都不支持match方式,最接近的方式是使用XSLT3处理器以及静态参数和阴影属性,例如_match。这需要使用像Saxon-C 1.2.1这样的XSLT3处理器及其Python绑定,尽管我目前不确定该设置对静态参数的支持程度。

文本值模板语法{$attributeValue}也仅由XSLT3处理器支持,甚至只有在XSLT中设置expand-text="yes"时才支持。

因此,XSLT1中唯一正确的用法是xsl:attribute name="{$attributeToBeAdded}"

最新更新