XSLT 转换(性能相关查询)
我正在使用以下代码片段进行 xml 文档的转换:
<xsl:for-each select="document('POC.XML')/a/b/Outputs/*">
<ns0:xyz xmlns:ns0="http://ratabase.cgi.com/">
<ns0:na>
<xsl:value-of select="local-name()" />
</ns0:na>
<ns0:Val>
<xsl:value-of select="." />
</ns0:Val>
</ns0:Rat>
</xsl:for-each>
我想知道使用 (
) 在大型应用程序中使用文档函数与 for-each 语句结合使用?
我用来转换 xml 的一种方法是使用下面给出的语法:
<xsl:variable name="var:xmldoc" select="document('POC.XML')/a/b/c/d/Outputs"/>
<xsl:copy-of select="$var:xmldoc"/>
我还想知道是否有任何替代方法适用于完成上述转换。
I am doing the transformation of an xml document using the following code snippet:
<xsl:for-each select="document('POC.XML')/a/b/Outputs/*">
<ns0:xyz xmlns:ns0="http://ratabase.cgi.com/">
<ns0:na>
<xsl:value-of select="local-name()" />
</ns0:na>
<ns0:Val>
<xsl:value-of select="." />
</ns0:Val>
</ns0:Rat>
</xsl:for-each>
I would like to know if there is any performance hit using (<xsl:for-each select="document('POC.XML')/a/b/Outputs/*">
) using the document function in conjunction with the for-each statement when used in large scale applications?
One approach that I am using to transform the xml is by using the syntax given below:
<xsl:variable name="var:xmldoc" select="document('POC.XML')/a/b/c/d/Outputs"/>
<xsl:copy-of select="$var:xmldoc"/>
I would also like to know whether any alternate methods are applicable to accomplish the above transformation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
性能完全取决于您使用的 XSLT 处理器;如果不说明您所询问的处理器是什么,那么询问性能问题是没有意义的。我希望大多数 XSLT 处理器能够非常有效地处理此构造(它们当然不会重复解析文档),但可能会有例外。
如果您想知道一种构造是否比另一种更快,请对其进行测量。猜测性能是没有意义的 - 如果您无法衡量差异,那么就无需担心差异。
你的第二个代码示例非常晦涩。好的,您选择一些节点,然后复制它们。您不会说明为什么要复制它们 - 通常在 XSLT 中您不需要复制内容,因为您可以像原始文件一样工作。
Performance depends entirely on the XSLT processor you are using; there's no point asking a performance question without saying what processor you are asking about. I would expect most XSLT processors to handle this construct quite efficiently (they certainly won't parse the document repeatedly) - but there may be exceptions.
If you want to know whether one construct is faster than another, then measure it. There's no point speculating about performance - if you can't measure the difference, then there isn't a difference to worry about.
You second code sample is pretty obscure. OK, you select some nodes and then you copy them. You don't say why you are copying them - usually in XSLT you don't need to copy things, because you can work just as well with the original.