Reputation: 1873
I am trying to learn XSLT and I face some difficulties implementing my goal.
The goal is xml document that will have a tag test-report
which will contain two attributes: start
and stop
. The start attribute will tell us when the test-suit execution has started and the stop attribute will tell when it ended (in current time)
<test-report start="{current-dateTime()}" stop="The time at the end of the transformation">
<xsl:call-template name="Test_suit_1"/>
</test-report>
During the processing of Test_suit_1
template, the time (current time) will progress. The tricky part (for me) is that the value of the stop
attribute must match the time at the end of the Test_suit_1
processing. In order to become a bit more clear in my question, the next pseudo code (which is illegal) will show what I am trying to achieve (if don't get it yet).
<test-report start="{current-dateTime()}">
<xsl:call-template name="temp"/>
<xsl:attribute name="stop"><xsl:value-of select="current-dateTime()"/></xsl:attribute>
</test-report>
Is it possible at all?
Upvotes: 0
Views: 41
Reputation: 21641
Short answer: No.
XSLT doesn't work this way. The basic problem is that you're thinking procedureally: you want the processor to do X, Y, and Z in that order and then go back and modify what was done at step X.
The processor is going to organize your templates in the way that follows the directives in the stylesheet and is most optimal according to its algorithms. It might do X, Z, and then Y, or do all three in parallel, or any other combination of the above. It's going to write the result tree following the directives in the templates, and never modify that result tree that you've declared in those directives. So once you write the time out as an attribute, it's there. In fact, (as pointed out by @MichaelKay in a comment on this post), if your processor is following the spec (ver1/2 or ver3), it should return the same value every time current-dateTime()
is called in the stylesheet - which makes a lot of sense when you consider how XSLT processors actually work.
You could achieve this by running a second template after the first to create a new result tree with updated stop
attributes, but that's still not going to give you what you seem to want (i.e. something like a .NET System.Diagnostics.Stopwatch
for an XSLT processor).
Upvotes: 1