xsl-list
[Top] [All Lists]

[xsl] Write to and read form same file

2007-09-20 12:14:39
Hi List

In the XSLT 2.0 spec I have problems understanding the following:

"It is a recoverable dynamic error for a stylesheet to write to an
external resource and read from the same resource during a single
transformation, whether or not the same URI is used to access the
resource in both cases. The optional recovery action is
implementation-dependent: implementations are not required to detect
the error condition. Note that if the error is not detected, it is
undefined whether the document that is read from the resource reflects
its state before or after the result tree is written."

Is it a bug in XMLSpy 2008 that document() works anyway? It does not
in SAXON. Is it a bug in SAXON that collection() works anyway?

Here is a stylesheet for writing to and reading from same file both in
AltovaXML and SAXON:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:template match="/">
 <xsl:result-document href="test.xml">
  <a>
   <b>Altova</b>
   <c>SAXON</c>
 </a>
 </xsl:result-document>
<test>
 <xsl:choose>
  <xsl:when test="system-property('xsl:product-name') eq 'Altova XSLT Engine'">
  <!-- document() should return error in this case but it works (!) in
XMLSpy 2008 -->
   <xsl:value-of select="document('test.xml')/a/b"/>
  </xsl:when>
  <xsl:when test="system-property('xsl:product-name') eq 'SAXON'">
  <!-- document() returns error as it should in SAXON. But
collection() works (!) -->
   <xsl:value-of select="collection(iri-to-uri('?select=test.xml'))/a/c"/>
  </xsl:when>
  <xsl:otherwise>
   <warning>This code example does not include <xsl:value-of
select="system-property('xsl:product-name')"/>.<xsl:text/>
   </warning>
  </xsl:otherwise>
 </xsl:choose>
</test>
</xsl:template>
</xsl:stylesheet>

Cheers,

Jesper Tverskov
www.xmlplease.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>