正在从xm中删除签名

2024-04-26 23:02:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想放弃xml文件中的signature元素。因此,我使用xslt从xml文件中过滤一些元素和标记。我在python中使用xslt。Xslt如下所示:

xslt_root = etree.XML('''\
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

                <xsl:template match="node() | @*">
                  <xsl:copy>
                      <xsl:apply-templates select="node() | @*"/>
                  </xsl:copy>
                </xsl:template>


                <xsl:template match="TimeStamp"/>
                <xsl:template match="@timeStamp"/>
                <xsl:template match="TimeStamps"/>
                <xsl:template match="Signature"/>

                </xsl:stylesheet>
                ''')

问题是,当我保存结果(更新的)xml文件时,我在xslt规则中定义的所有元素和标记都将被丢弃,只剩下“Signature”元素。有没有可能从xml文件中丢弃此签名?在


Tags: 文件标记node元素matchtemplaterootxml
1条回答
网友
1楼 · 发布于 2024-04-26 23:02:31

如果您的Signature元素具有名称空间,例如:

  <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature>

然后需要调整XSLT,使其与命名空间匹配:

^{pr2}$

相关问题 更多 >