Re: Preserving the base URI through a p:xslt transformation

About p:xslt's output-base-uri option, I noticed this behavior before and was not quite sure it was a bug in Calabash until I read into more details today.

Basically, the XSLT 2.0 spec says [1] "The base output URI is a URI to be used as the base URI when resolving a relative URI allocated to a final result tree". Additionally, the final result tree created by a stylesheet's initial template with no xsl:result-document child (the "primary" result tree) his equivalent to one that w/b created with a single xsl:result-document with an empty @href. By combining the two rules, you get that the base URI of the "primary" final result tree is indeed set by the base output URI.

Anyway, there's lot of implied stuff here, and I suppose the XProc wording wouldn't hurt by explicitly stating that a consequence of the output-base-uri option is to set the base URI of the result document.

Romain.

[1] http://www.w3.org/TR/xslt20/#initiating
[2] http://www.w3.org/TR/xproc/#c.xslt


On 22 mars 2013, at 12:08, Jostein Austvik Jacobsen <josteinaj@gmail.com> wrote:

> Thanks for the detailed response. I tried output-base-uri now, but unfortunately it didn't help:
> 
> <p:with-option name="output-base-uri" select="base-uri(/*)"/>
> 
> Yes, I am indeed using calabash version 1.0.8.94 (in oXygen 14.2).
> 
> So a workaround for now can be something like this:
> 
>     <p:group>
>         <p:variable name="base" select="base-uri(/*)"/>
>         <p:xslt>
>             ...
>         </p:xslt>
>         <p:choose>
>             <p:when test="/*[@xml:base]">
>                 <p:identity/>
>             </p:when>
>             <p:otherwise>
>                 <p:add-attribute match="/*" attribute-name="xml:base">
>                     <p:with-option name="attribute-value" select="$base"/>
>                 </p:add-attribute>
>                 <p:delete match="/*/@xml:base"/>
>             </p:otherwise>
>         </p:choose>
>     </p:group>
> 
> Thanks!
> Jostein
> 
> 
> On 22 March 2013 11:28, James Fuller <jim@webcomposite.com> wrote:
> On Fri, Mar 22, 2013 at 10:50 AM, Jostein Austvik Jacobsen
> <josteinaj@gmail.com> wrote:
> > So this pipeline:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="1.0">
> >     <p:input port="source">
> >         <p:inline>
> >             <doc xml:base="file:/tmp/"/>
> >        </p:inline>
> >     </p:input>
> >     <p:output port="result"/>
> >     <p:delete match="/*/@xml:base"/>
> >     <p:add-attribute match="/*" attribute-name="base-before">
> >         <p:with-option name="attribute-value" select="base-uri(/*)"/>
> >     </p:add-attribute>
> >     <p:xslt>
> >         <p:input port="parameters">
> >             <p:empty/>
> >         </p:input>
> >         <p:input port="stylesheet">
> >             <p:inline>
> >                 <xsl:stylesheet
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
> >                     <xsl:template match="/">
> >                         <xsl:copy-of select="/"/>
> >                     </xsl:template>
> >                 </xsl:stylesheet>
> >             </p:inline>
> >         </p:input>
> >     </p:xslt>
> >     <p:add-attribute match="/*" attribute-name="base-after">
> >         <p:with-option name="attribute-value" select="base-uri(/*)"/>
> >     </p:add-attribute>
> > </p:declare-step>
> >
> > Gives me this on the output port:
> >
> > <doc base-after="file:/home/jostein/preserve-base-test.xpl"
> > base-before="file:/tmp/"/>
> >
> > I would like to get this:
> >
> > <doc base-after="file:/tmp/" base-before="file:/tmp/"/>
> >
> > How can I make an XSLT transformation preserve the base URI of the document
> > without using the xml:base attribute?
> 
> note that p:xslt has a output-base-uri option
> 
> verbatim from the spec
> 
> 'The output-base-uri option sets the context's output base URI per the
> XSLT 2.0 specification, otherwise the base URI of the result document
> is the base URI of the first document in the source port's sequence.
> If the value of the output-base-uri option is not absolute, it will be
> resolved using the base URI of its p:option element. An XSLT 1.0 step
> should use the value of the output-base-uri as the base URI of its
> output, if the option is specified.'
> 
> so you first set the base uri explicitly,
> then you delete the attribute
> then you dowse it back,
> finally pushing it through xslt meat grinder….
> 
> the statement from the spec
> 
> 'otherwise the base URI of the result document is the base URI of the
> first document in the source port's sequence'
> 
> when you delete the attribute, this does not affect base-uri (because
> delete attribute is not deleting its actual base-uri) … I think the
> problem is that the p:xslt step then goes and implies a base-uri on
> its own and its probably a bug but (assuming you are using calabash)
> will let impl comment further.
> 
> if it helps, I think your expectation is valid and your example a good
> candidate for a new unit test which I will try to fold into the w3c
> xproc unit test suite.
> 
> hth, Jim Fuller
> 

Received on Friday, 22 March 2013 12:00:54 UTC