Reputation: 433
I was wondering if there is a non-recursive alternative to the simple and clean recursive XSLT identity transformation (below)? I have been told XSLT recursive templates can have an impact on performance so I might not be allowed to use them in my current project.
Identity transformation template:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
Thanks in advance!
Upvotes: 0
Views: 283
Reputation: 12075
If you REALLY want to avoid recursion, you've basically got three options:
Use one template, matching the document (/
) and do all your output
inside that template, without any use of <xsl:apply-templates>
.
However, this is exceptionally bad XSLT design.
Use a literal result element- Your entire stylesheet is actually just
output xml/html, but with the xsl namespace declared, and at key
points using an <xsl:value-of/>
instruction. EDIT: Thinking about it, this is pretty much the same as the first option.
Refuse the task, if you can (recommended).
Upvotes: 2
Reputation: 111491
The question itself is misguided.
Express your transformation in its most elegant form, let the XSLT processor worry about optimizations, actually measure performance -- don't guess, and then optimize actual bottlenecks.
Chances are good that you'll have no performance problems requiring further attention anyway.
Upvotes: 2
Reputation: 116959
Your question is not entirely clear. The identity transform is used because it provides an opportunity to override it for some nodes by using another, more specific, template. This is possible because the identity transform is recursive.
If you only want to copy everything as is, without any exceptions, you could use simply:
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
Whether this will improve performance is another question.
Upvotes: 1