transform() and -now
Added by T Hata about 5 years ago
Is there a way to propagate -now
to the stylesheet invoked by transform()
?
I'm not sure how the calling environment and the invoked transformation are supposed to be connected.
When I run this stylesheet
calling.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="#all" version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" omit-xml-declaration="yes" />
<xsl:template name="xsl:initial-template">
<calling>
<xsl:value-of select="current-dateTime()" />
</calling>
<xsl:sequence
select="
transform(map {'stylesheet-location': 'invoked.xsl'})
?output" />
</xsl:template>
</xsl:stylesheet>
with this stylesheet
invoked.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="#all" version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="xsl:initial-template">
<invoked>
<xsl:value-of select="current-dateTime()" />
</invoked>
</xsl:template>
</xsl:stylesheet>
and -now
option, then I get this
C:\test>java -jar saxon9ee.jar -it -now:1212-12-12T12:12:12Z -t -xsl:calling.xsl
Saxon-EE 9.9.1.5J from Saxonica
Java version 12.0.1
...
<calling>1212-12-12T12:12:12Z</calling>
<invoked>2019-09-20T14:40:23.529101-07:00</invoked>
...
Replies (1)
RE: transform() and -now - Added by Michael Kay about 5 years ago
The called transformation shares the same Saxon Configuration
as the calling transformation, but it runs in a different execution scope (which in terms of Saxon internals, means a different Controller
). The current date/time is a property of the execution scope: so even if you don't set the current date/time artificially, it will be different between the calling and called transformations,
Although the command line and the Controller
API (but not the s9api API) allow the current date/time to be set -- mainly for testing purposes -- this doesn't extend to the fn:transform() function.
So I'm afraid the answer is no,
Incidentally, another part of the execution scope that isn't shared between the calling and called transformations is the document pool. This means you can use fn:transform() to bypass restrictions such as not being allowed to read a document that was written in the same transformation.
This differs from xsl:evaluate, where the dynamic expression runs in the same execution scope as the caller.
Please register to reply