Skip to content

Commit

Permalink
transform pipelines accept items castable as xs:string as value fur r…
Browse files Browse the repository at this point in the history
…elative URI
  • Loading branch information
fsteimke committed Jan 4, 2024
1 parent e9280d5 commit 1fbf31e
Showing 1 changed file with 63 additions and 50 deletions.
113 changes: 63 additions & 50 deletions src/main/xslt/docbook.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:db="http://docbook.org/ns/docbook"
xmlns:dbe="http://docbook.org/ns/docbook/errors"
xmlns:err='http://www.w3.org/2005/xqt-errors'
xmlns:ext="http://docbook.org/extensions/xslt"
xmlns:f="http://docbook.org/ns/docbook/functions"
xmlns:fp="http://docbook.org/ns/docbook/functions/private"
Expand Down Expand Up @@ -101,43 +102,67 @@
</xsl:map-entry>
</xsl:map>
</xsl:variable>

<xsl:variable name="vp:transforms" as="map(*)*">
<xsl:for-each select="$transform-original">
<xsl:choose>
<xsl:when test=". instance of map(*)">
<xsl:sequence select="."/>
</xsl:when>
<xsl:when test=". instance of xs:string">
<xsl:sequence select="map {
'stylesheet-location': resolve-uri(., base-uri(/))
}"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="error($dbe:INVALID-TRANSFORM,
'Each $transform-original must be a string or a map')"/>
</xsl:otherwise>
</xsl:choose>

<xsl:template name="tp:stylesheet-locations" as="map(xs:string, xs:string)*">
<xsl:param name="locations" as="item()*"/>
<xsl:param name="purpose" as="xs:string"/>
<xsl:variable name="base-uri" as="xs:anyURI?">
<xsl:try>
<xsl:sequence select="base-uri(/)"/>
<xsl:catch/>
</xsl:try>
</xsl:variable>
<xsl:for-each select="$locations">
<xsl:choose>
<xsl:when test=". instance of map(xs:string, xs:string)">
<xsl:sequence select="."/>
</xsl:when>
<xsl:when test="not(exists($base-uri))">
<xsl:message
select="'WARNING: cannot resolve URI ' || xs:string(.) || ' in $' || $purpose || ': context item is absent.'"
/>
</xsl:when>
<xsl:when test=". castable as xs:string">
<xsl:try>
<xsl:variable name="uri" as="xs:anyURI" select="resolve-uri(xs:string(.), $base-uri)"/>
<xsl:choose>
<xsl:when test="doc-available($uri)">
<xsl:sequence select="
map {
'stylesheet-location': xs:string($uri)
}"/>
</xsl:when>
<xsl:otherwise>
<xsl:message
select="'WARNING: cannot find resolved URI ' || $uri || ' in $' || $purpose"/>
</xsl:otherwise>
</xsl:choose>
<xsl:catch>
<xsl:message
select="'WARNING: cannot resolve URI ' || xs:string(.) || ' in $' || $purpose || ': ' || $err:description"
/>
</xsl:catch>
</xsl:try>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="
error($dbe:INVALID-TRANSFORM,
'Each $' || $purpose || ' must be a string or a map')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>

<xsl:variable name="vp:transforms" as="map(*)*">
<xsl:call-template name="tp:stylesheet-locations">
<xsl:with-param name="locations" select="$transform-original"/>
<xsl:with-param name="purpose" select="'transform-original'"/>
</xsl:call-template>
<xsl:sequence select="$v:standard-transforms"/>

<xsl:for-each select="$transform-before">
<xsl:choose>
<xsl:when test=". instance of map(*)">
<xsl:sequence select="."/>
</xsl:when>
<xsl:when test=". instance of xs:string">
<xsl:sequence select="map {
'stylesheet-location': resolve-uri(., base-uri(/))
}"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="error($dbe:INVALID-TRANSFORM,
'Each $transform-preprocessed must be a string or a map')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:call-template name="tp:stylesheet-locations">
<xsl:with-param name="locations" select="$transform-before"/>
<xsl:with-param name="purpose" select="'transform-before'"/>
</xsl:call-template>
</xsl:variable>

<!-- If a document or element is being processed in the default
Expand Down Expand Up @@ -223,22 +248,10 @@
</xsl:variable>

<xsl:variable name="post-processing" as="map(*)*">
<xsl:for-each select="$transform-after">
<xsl:choose>
<xsl:when test=". instance of map(*)">
<xsl:sequence select="."/>
</xsl:when>
<xsl:when test=". instance of xs:string">
<xsl:sequence select="map {
'stylesheet-location': resolve-uri(., base-uri(/))
}"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="error($dbe:INVALID-TRANSFORM,
'Each $transform-preprocessed must be a string or a map')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:call-template name="tp:stylesheet-locations">
<xsl:with-param name="locations" select="$transform-after"/>
<xsl:with-param name="purpose" select="'transform-after'"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="result" as="document-node()">
Expand Down

0 comments on commit 1fbf31e

Please sign in to comment.