Re: own defined step and xml:base "inheritance"

Thank you Jostein for your testing !

You're right, when I give an inline (irrelevant) xml content for the $href
option, the base-uri mecanism is applied, it sounds good, I think I start
to understand !

My interpretation is as follow :
Xproc is about stream of XML within pipelines. XML can either flow through
an input or output port. Feeding this ports can be done :
- either by loading an external document with <p:document>
- or by the writing it directly in the pipelin with <p:inline>.
That means the xproc processor should care of xml:base only for
<p:document> and <p:inline>, this is hard coded and user can't change this
! (?)
So I will never be able to define a custom step with an $href option which
works like document/@href ! That's all, and it has nothing to do with the
implementation (calabash or other).

Is it correct ?


Then, for my problem I can do :

<p:import href="common.xpl"/>
<p:pipeline type="igs:xml2ecf" xml:base="file:///C:/foo/bar/">
    <igs:xslt href="xsl/my.xsl">
        <p:with-option name="base-uri"
select="base-uri()"><p:inline><irrelevant/></p:inline></p:with-option>
    </igs:xslt>
</p:pipeline>

common.xpl :
<p:declare-step type="igs:xslt" name="current">
  <p:option name="href" required="true" /> <!-- cx:type="xsd:anyURI" is
useless -->
  <p:option name="base-uri" select="base-uri()"/>
  <p:load name="load_stylesheet">
      <p:with-option name="href" select="resolve-uri($href,$base-uri)"/>
    </p:load>
   <p:xslt>...</p:xslt>
</p:declare-step>

But this is still a bit verbose to pass the base-uri for each xslt. My goal
is to make the first file (call "profile.xpl")  as simple as possible (see
"the context" at  http://markmail.org/thread/ih72ahgckiuejb4o).
For example :

<p:import href="common.xpl"/>
<p:pipeline type="igs:xml2ecf" xml:base="file:///D:/res/common/xsl/">
    <igs:xslt href="xsl/step1.xsl"/>
    <igs:xslt href="xsl/step2.xsl"/>
    <igs:xslt href="xsl/step3.xsl" xml:base="file:///C:/local/res/xsl"/>
    <igs:xslt href="xsl/step4.xsl"/>
    <igs:xslt href="xsl/step5.xsl" xml:base="
http://www.igs-cp.fr/net/res/xsl"/>
</p:pipeline>

As you see there is not only one xml:base to care, the user define the most
usefull xml:base for his resssources and then can make exception when
necessary.
I would have like the file to keep so simple as this sample but I guess
this will be difficult.

Continuing investigation.

Thanks for your help.

Regards,
Matthieu





2013/12/16 Jostein Austvik Jacobsen <josteinaj@gmail.com>

> Yes, it's probably better to use "/*" than ".". Also, I just remembered
> that the select expression uses the primary input document as context
> (doh!), I should've tested it before replying the first time.
>
> Try this pipeline:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="
> http://www.w3.org/ns/xproc-step" version="1.0" xml:base="
> http://example.net/script.xpl">
>
>     <p:input port="source">
>         <p:inline xml:base="file:/tmp/some-input-document.xml">
>             <c:result/>
>         </p:inline>
>     </p:input>
>     <p:output port="result"/>
>
>     <!-- the default context for the select attribute is the primary input
> document -->
>     <p:add-attribute match="/*"
> attribute-name="base-uri-from-primary-input">
>         <p:with-option name="attribute-value" select="base-uri(/*)"/>
>     </p:add-attribute>
>
>     <!-- inline documents defaults to the same base URI as the current
> XProc document -->
>     <p:add-attribute match="/*"
> attribute-name="base-uri-from-inline-document">
>         <p:with-option name="attribute-value" select="base-uri(/*)">
>             <p:inline>
>                 <irrelevant/>
>             </p:inline>
>         </p:with-option>
>     </p:add-attribute>
>
>  </p:declare-step>
>
>
> It will give you this:
>
>
> <c:result xmlns:c="http://www.w3.org/ns/xproc-step"
> base-uri-from-primary-input="file:/tmp/some-input-document.xml"
> base-uri-from-inline-document="http://example.net/script.xpl"/>
>
>
> Note how you need to provide a inline document to be able to access the
> base URI of the xproc document. You will often need to refer to the xproc
> documents base URI several times, so it might be a good idea to store it in
> a variable at the beginning of the pipeline like this:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="
> http://www.w3.org/ns/xproc-step" version="1.0" xml:base="
> http://example.net/script.xpl">
>
>     <p:input port="source">
>         <p:inline xml:base="file:/tmp/some-input-document.xml">
>             <c:result/>
>         </p:inline>
>     </p:input>
>     <p:output port="result"/>
>
>     <p:variable name="base-uri" select="base-uri(/*)">
>         <p:inline>
>             <irrelevant/>
>         </p:inline>
>     </p:variable>
>
>     <!-- use the variable to pass the xml:base to the step (replace
> p:add-attribute with your own step) -->
>     <p:add-attribute match="/*" attribute-name="base-uri-from-variable">
>         <p:with-option name="attribute-value" select="$base-uri"/>
>     </p:add-attribute>
>
> </p:declare-step>
>
>
> Which gives you this:
>
>
> <c:result xmlns:c="http://www.w3.org/ns/xproc-step"
> base-uri-from-variable="http://example.net/script.xpl"/>
>
>
> Jostein
>
>
> On 16 December 2013 11:52, Imsieke, Gerrit, le-tex <
> gerrit.imsieke@le-tex.de> wrote:
>
>> Try base-uri(/*) since the uri will be set by the attribute on the
>> top-level element rather than on the document node around that element.
>>
>>
>> On 16.12.2013 11:05, RICAUD-DUSSARGET Matthieu wrote:
>>
>>> Hi Jostein,
>>>
>>> Thanks for your answer.
>>>
>>> I tried both of your solutions but unfortunately the value of base-uri()
>>> is always the *base-uri of the xml file being processed* and not what I
>>> wrote in the xml:base attribute :-(
>>>
>>> On the other hand my goal is actually to make the pipeline as simple and
>>> as short as possible : I would really like to use it <igs:xslt
>>> href="..."> exactly like <p:document href="..."/> which automaticaly
>>> resolve the uri according to the xml:base without I need to tell it.
>>>
>>> This is important because the first xpl file will be used as a kind of
>>> "profile file" for non xproc developpers, it really has to keep less
>>> verbose as possible.
>>>
>>> Anyway you are right about xml:base, this is not "inheritance" (I wrote
>>> it with quotes on this purpose), it's rather "implementation of xml:base
>>> with declared steps".
>>>
>>> Thanks for your help.
>>>
>>> Cheers
>>>
>>> Matthieu
>>>
>>> PS : INFO
>>> XML Calabash version 1.0.3 (for Saxon 9.4.x), an XProc processor.
>>> Running on Saxon version 9.4.0.2, HE edition.
>>> I'm not able to run my pipeline with Calabash1.0.16 because of another
>>> problem I will explain in another post.
>>>
>>>
>>>
>>>
>>>
>>>
>>> 2013/12/16 Jostein Austvik Jacobsen <josteinaj@gmail.com
>>> <mailto:josteinaj@gmail.com>>
>>>
>>>
>>>     You could resolve the URI each time you invoke your step:
>>>
>>>     <p:import href="common.xpl"/>
>>>     <p:pipeline type="igs:xml2ecf" xml:base="file:///C:/foo/bar/">
>>>          <igs:xslt>
>>>              <p:with-option name="href"
>>>     select="resolve-uri('xsl/igs/v2.5/main_igs_v2.5.xsl',
>>> base-uri(.))"/>
>>>          </igs:xslt>
>>>     </p:pipeline>
>>>
>>>     Alternatively, you could add a base-uri option to your step:
>>>
>>>     <p:import href="common.xpl"/>
>>>     <p:pipeline type="igs:xml2ecf" xml:base="file:///C:/foo/bar/">
>>>          <igs:xslt href="xsl/igs/v2.5/main_igs_v2.5.xsl">
>>>              <p:with-option name="base-uri" select="base-uri(.)"/>
>>>          </igs:xslt>
>>>     </p:pipeline>
>>>
>>>     The base URI of p:with-option in your last example is (almost
>>>     certainly) an absolute file URI pointing to the file you declared
>>>     igs:xslt in. The xml:base is not "inherited" in any way, and there's
>>>     no "tunneling" mechanism that could be used like there is in XSLT
>>>     (although I wish there were).
>>>
>>>     Hope this helps.
>>>
>>>
>>>     Jostein
>>>
>>>
>>>     On 16 December 2013 09:50, RICAUD-DUSSARGET Matthieu
>>>     <matthieu.ricaud@igs-cp.fr <mailto:matthieu.ricaud@igs-cp.fr>>
>>> wrote:
>>>
>>>         Hi all,
>>>
>>>         I'm using Calabash. I don't know if the problem comes from xproc
>>>         implementation or just xproc dev.
>>>
>>>         When I use a pipeline with an xml:base attribute, I can use
>>>         p:xslt with p:document/@href relative to this xml:base :
>>>
>>>            <p:pipeline type="igs:xml2ecf" xml:base="file:///C:/foo/bar/"
>>> >
>>>                <p:xslt>
>>>                  <p:input port="stylesheet"><p:document
>>>         href="xsl/my.xsl"/></p:input>
>>>                </p:xslt>
>>>            </p:pipeline>
>>>
>>>         As long as file:///C:/foo/bar/xsl/my.xsl exists, it works,
>>> perfect !
>>>
>>>         But when I want to override p:xslt with my own step in a
>>>         library, it doesn't work anymore :
>>>
>>>            <p:import href="common.xpl"/>
>>>            <p:pipeline type="igs:xml2ecf" xml:base="file:///C:/foo/bar/"
>>> >
>>>                <igs:xslt href="xsl/igs/v2.5/main_igs_v2.5.xsl"/>
>>>            </p:pipeline>
>>>
>>>         where common.xpl defines :
>>>         _
>>>
>>>         _
>>>         <p:declare-step type="igs:xslt" name="current">
>>>              <p:input port="source" sequence="true" primary="true"/>
>>>              <p:input port="parameters" kind="parameter"/>
>>>              <p:output port="result" primary="true"/>
>>>              <p:option name="href" required="true" cx:type="xsd:anyURI"/>
>>>              <p:load name="load_stylesheet"><p:with-option name="href"
>>>         select="$href"/></p:load>
>>>              <p:xslt>
>>>                  <p:input port="stylesheet">
>>>                      <p:pipe port="result" step="load_stylesheet"/>
>>>                  </p:input>
>>>                  <p:input port="source">
>>>                      <p:pipe port="source" step="current"/>
>>>                  </p:input>
>>>                  <p:input port="parameters">
>>>                      <p:pipe port="parameters" step="current"/>
>>>                  </p:input>
>>>              </p:xslt>
>>>              <ut:log>
>>>                <p:with-option name="href"
>>>         select="resolve-uri($debug_fileName, base-uri(.))"/>
>>>              </ut:log>
>>>            </p:declare-step>
>>>
>>>         I have added cx:type="xsd:anyURI" on href option so it is affect
>>>         by xml:base but it doesn't work either.
>>>
>>>         I get an error because the xsl file is not available in the same
>>>         folder as the xpl file.
>>>
>>>         Of course I can add the xml:base on "igs:xslt" p:declare-step
>>>         and it works. But this step is a common one and the goal is to
>>>         be able to call it with a different xml:base each time.
>>>
>>>         Do you have any advices or ideas to solve this ?
>>>
>>>         Thanks in advance,
>>>
>>>         Matthieu
>>>
>>>
>>>         --
>>>         Matthieu Ricaud-Dussarget
>>>         IGS-CP - Développeur XML
>>>         05 45 37 09 49
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Matthieu Ricaud-Dussarget
>>> IGS-CP - Développeur XML
>>> 05 45 37 09 49
>>>
>>
>>
>


-- 
Matthieu Ricaud-Dussarget
IGS-CP - Développeur XML
05 45 37 09 49

Received on Monday, 16 December 2013 17:18:38 UTC