[英]XSLT use concat or multiple value-of elements to join variables?
Assume I have like 20 variables that I want to join to a csv string.假设我有 20 个变量想要加入到 csv 字符串中。 Should I prefer
concat()
, or just place all variables below each other in <xsl>
elements?我应该更喜欢
concat()
,还是将所有变量放在<xsl>
元素中?
either:任何一个:
<xsl:value-of select="concat($var1, ';', ..., $var10)"/>
or:或者:
<xsl:value-of select="$var1"/>
<xsl:text>;</xsl:text>
...
<xsl:value-of select="$var10"/>
Especially regarding to performance, as I have hundred million rows to process.特别是在性能方面,因为我有数亿行要处理。
Is the contact
approach similar to a java
StringBuilder
, and the element approach similar to a string += val
reassignment? contact
方式是否类似于java
StringBuilder
,元素方式是否类似于string += val
重新分配? If the, the concat
would of course be superior.如果是,则
concat
当然会更好。 But is that true?但这是真的吗?
It's very unlikely there will be a measurable performance difference, but the only way to find out is to measure it.不太可能会有可测量的性能差异,但找出答案的唯一方法就是测量它。
In Saxon a concat()
call will always build the string in memory (until the next Saxon release...) while a series of xsl:text
/ xsl:value-of
calls will (where possible) write it incrementally to the serializer, so that might make a difference to memory usage if the string is extremely large.在 Saxon 中,
concat()
调用将始终在 memory 中构建字符串(直到下一个 Saxon 版本...),而一系列xsl:text
/ xsl:value-of
调用将(在可能的情况下)将其增量写入序列化程序,因此,如果字符串非常大,这可能会对 memory 的使用产生影响。
At least I found out by profiling that contact()
performed 25% better than multiple xsl:text/xsl:value-of
calls.至少我通过分析发现,
contact()
的性能比多个xsl:text/xsl:value-of
调用好 25%。 But I don't know if that can be said in general, but in my case with hundred millions of rows that's it.但我不知道这是否可以笼统地说,但就我而言,数亿行就是这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.