使用 xslt3.0 从 xml 中删除某些节点 [英] Remove certain nodes from an xml using xslt3.0

查看:46
本文介绍了使用 xslt3.0 从 xml 中删除某些节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在尝试使用 xslt3.0 使用身份模板从 xml 中删除某些节点.但这需要很长时间的处理时间.需要一些建议以提高使用 Xslt30Transformer 的性能.

Currently i am trying to remove certain nodes from an xml using xslt3.0 using identity template. But this is taking long processing time. need some suggestion to improve performace using Xslt30Transformer.

<xsl:stylesheet version="3.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/">
 <xsl:output method="xml" indent="yes"/>

 <xsl:variable name="pathexcluded" select="'CATALOG/CD1 | CATALOG/CD2 '"/>
 <xsl:variable name="changed-nodes" as="node()*" >
  <xsl:evaluate xpath="$pathexcluded" context-item="/"/>
 </xsl:variable>

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

 
 <xsl:template match="$changed-nodes">
</xsl:template>
</xsl:stylesheet>

推荐答案

一个性能问题只有在你可以量化它时才有意义:源文档的大小是多少,它需要多长时间,这与您的性能要求?

A performance question really only makes sense if you can quantify it: what is the size of the source document, how long is it taking, how does this compare with your performance requirement?

我不明白你为什么在这里使用 xsl:evaluate,因为路径表达式是固定的.也许它没有在您的真实代码中修复?但是,如果这不是您的真实代码,那么您可能还没有向我们展示问题的实际根源?当然,如果它是一个大型源文档并且您只评估一次 xsl:evaluate,那么它不太可能是问题的原因.

I can't see why you're using xsl:evaluate here, given that the path expression is fixed. Perhaps it isn't fixed in your real code? But then, if this isn't your real code, perhaps you haven't shown us the actual source of the problem? Certainly if it's a large source document and you're only evaluating the xsl:evaluate once, then it's unlikely to be the cause of the trouble.

如果 $changed-nodes 是一个非常大的节点, 可能是一个问题-放.我有一种感觉,我们最近做了一些工作来解决这个问题:您没有说明您使用的是哪个 Saxon 版本.但即使有了这些改进,测试每个节点以查看它是否符合删除标准也比形成所有此类节点的集合然后测试每个节点以查看它是否是该集合的成员要好.

The <xsl:template match="$changed-nodes"/> might well be a problem if $changed-nodes is a very large node-set. I have a feeling we did some work recently to address this: you haven't said which Saxon release you are using. But even with those improvements, testing each node to see whether it matches the criteria for deletion is going to be better than forming the set of all such nodes and then testing each node to see whether it is a member of that set.

这篇关于使用 xslt3.0 从 xml 中删除某些节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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