Problem with collection() and fetch()
Graydon Saunders <[email protected]> Wed, 9 Sep 2020 12:30:39 -0400
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <CAO3ciQEtK-PKOPtsoO6edyT0RH74xXiuktAQhZpLbBVh42n+GQ@mail.gmail.com> |
Hello --
I'm using Saxon from inside Oxygen XML Editor. I get the same error with
Saxon-PE or Saxon-EE. Saxon version is 9.9.1.7; oXygen version
is <oXygen/> XML Editor 22.1, build 2020072902 just in case that might be
relevant.
I'm trying to use the metadata option to the collection function; this has
worked, but sometimes something happens in response to code changes
elsewhere in the main code and I start getting null pointer exceptions or
"variable not evaluated" problems with the "make a map from the collection"
step. I've reduced this to the small example below; this one consistently
gives me an internal error:
System ID: /home/graydon/PCAS/git/DITA2Word/xslt/fetch-test.xsl
Scenario: fetch-test
XSL file: /home/graydon/PCAS/git/DITA2Word/xslt/fetch-test.xsl
XML file:
/home/graydon/PCAS/git/dita-demo-content-collection/Thunderbird/User_Guide.ditamap
Engine name: Saxon-PE 9.9.1.7
Severity: error
Description: Internal error evaluating template rule at line 34 in module
file:/home/graydon/PCAS/git/DITA2Word/xslt/fetch-test.xsl
Note that this stylesheet returns $contentMap without complaint; trying to
produce $contentSet is what throws the error.
<xsl:stylesheet exclude-result-prefixes="xs math xd map" version="3.0"
xmlns:math="http://www.w3.org/2005/xpath-functions/math" xmlns:xd="
http://www.oxygenxml.com/ns/doc/xsl"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:map="http://www.w3.org/2005/xpath-functions/map">
<xd:doc scope="stylesheet">
<xd:desc>
<xd:p><xd:b>Created on:</xd:b> Sep 9, 2020</xd:p>
<xd:p><xd:b>Author:</xd:b> graydon</xd:p>
<xd:p />
</xd:desc>
</xd:doc>
<xsl:mode name="first" on-no-match="shallow-copy"/>
<!-- the source doc is a DITA map in a different directory -->
<xsl:variable as="xs:string" name="sourceDoc" select="base-uri(/)" />
<xsl:variable as="xs:string" name="sourceDir"
select="'/' || ($sourceDoc => tokenize('/'))[not(position() eq
last())][not(matches(., 'file:', 'i'))] => string-join('/')" />
<xsl:variable as="map(*)+" name="contentMap"
select="($sourceDir || '?recurse=yes;on-error=warning;metadata=yes') =>
collection()" />
<xsl:variable as="map(xs:string,document-node())" name="contentSet">
<xsl:map>
<xsl:for-each select="$contentMap">
<xsl:if test=".?content-type eq 'application/unknown'">
<xsl:map-entry key=".?name" select=".?fetch()">
<!--<xsl:apply-templates mode="first" select=".?fetch()" />-->
</xsl:map-entry>
</xsl:if>
</xsl:for-each>
</xsl:map>
</xsl:variable>
<xd:doc>
<xd:desc>we need a template</xd:desc>
</xd:doc>
<xsl:template match="/">
<!--<bucket>
<xsl:sequence select="$contentMap?name"></xsl:sequence>
</bucket>-->
<bucket>
<xsl:sequence select="$contentSet => map:keys()" />
</bucket>
</xsl:template>
</xsl:stylesheet>
If I use
<xsl:variable as="map(xs:string,document-node())" name="contentSet"
select="(for $m in $contentMap return if ($m?content-type eq
'application/unknown') then map:entry($m?name,$m?fetch()) else ()) =>
map:merge()" />
instead of the XSLT version (which I want so I can have the apply
templates) I get various type errors right up until the point I feed the
whole thing into map:merge() so that it's type correct. At that point I
get the same error as with the XSLT version:
System ID: /home/graydon/PCAS/git/DITA2Word/xslt/fetch-test.xsl
Scenario: fetch-test
XSL file: /home/graydon/PCAS/git/DITA2Word/xslt/fetch-test.xsl
XML file:
/home/graydon/PCAS/git/dita-demo-content-collection/Thunderbird/User_Guide.ditamap
Engine name: Saxon-EE 9.9.1.7
Severity: error
Description: Internal error evaluating template rule at line 34 in module
file:/home/graydon/PCAS/git/DITA2Word/xslt/fetch-test.xsl
The data set I'm using is a DITA test set at
https://github.com/gnostyx/dita-demo-content-collection and I'm using
Thunderbird/User_Guide.ditamap as the source document. Note that this is
outside the oXygen project where the xslt code resides, but moving it into
the project doesn't help; same error.
This approach works really well when it's working; with luck I'm doing
something wrong and easily fixed.
Thanks!
Graydon
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help