This works fine. Thank you very much !

with kind regards,

Emmy Detmar

-----Oorspronkelijk bericht-----
Van: Hussein Shafie [mailto:hussein at xmlmind.com] 
Verzonden: maandag 10 november 2008 18:57
Aan: Detmar, Emmy
CC: xmleditor-support at xmlmind.com
Onderwerp: Re: pdf creation

Detmar, Emmy wrote:

> I am using a (non standard) application for creating xml files. Now I
> have upgraded to version 3.8.1 pro because of the possibility to create
> pdf directly from xml mind.The Xep renderer is installed and works, this
> can be tested with the docbook application.
> 
>  
> 
> What I want to do now is let the user select an XSLT-FO stylesheet from
> a list and then generate a pdf with the selected stylesheet.
> 
> The XSLT-FO stylesheet are not yet ready so I am trying to work out how
> to do this with the docbook application.
> 
>  
> 
> I have written a command to present a list and to store the selected
> item in a parameter. The problem is to pass the parameter to the
> docb.ToPS command:
> 
>                 <transform stylesheet="xsl/fo/docbook.xsl"
> 
> so that the transform uses the selected stylesheet instead of docbook.xsl
> 
>  
> 
> Something like this:
> 
>  
> 
>   <command name="docb.kiesStijl">
> 
>     <macro trace="true">
> 
>       <sequence>
> 
>         <command name="pick"
> 
>                  parameter="'kies stijl' true
> 
>                             'docbook 1'
> 
>                             stijlA
> 
>                             'docbook 2'
> 
>                             stijlB" />
> 
>         <set variable="foo:stijl"
> 
>             
> xmlns:foo="http://www.xmlmind.com/xmleditor/namespace/scope/view";
> 
>              expression="%_" plainString="true" />
> 
>       </sequence>
> 
>     </macro>
> 
>   </command>
> 
>  
> 
>     <command name="docb.convertToPS">
> 
>     <macro>
> 
>       <sequence>
> 
>         <command name="docb.kiesStijl" />
> 
>         <command name="selectConvertedFile"
> 
>                  parameter="saveFileURLWithExtension=%0" />
> 
>         <command name="docb.toPSFile" parameter='"%0" "%1" "%2" "%3"
> "%_"' />
> 
>       </sequence>
> 
>     </macro>
> 
>   </command>
> 
>  
> 
>   <command name="docb.toPSFile">
> 
>     <process>
> 
>       <subProcess name="docb.toPS" parameter='"%0" "%1" "%2" "%3"' />
> 
>       <!-- nu de pdf verplaatsen -->
> 
>       <upload base="%4">
> 
>         <copyFile file="__doc.%0" to="%4" />
> 
>       </upload>
> 
>     </process>
> 
>   </command>
> 
>  
> 
>   <command name="docb.toPS">
> 
>     <process>
> 
>       <mkdir dir="resources" />
> 
>       <mkdir dir="raw" />
> 
> ... etc
> 
>  
> 
> (1) It seems logical to insert the <command name="docb.kiesStijl" />
> just before the transform in docb.toPS but that does not work (error
> message);
> 
> (2) The %_ parameter is already in use for something else so  < get
> expression="$foo:stijl" /> overwrites the "original %_
> 
> (3) and <get ? > does not work within process, just like <command ? >
> 
>  
> 
> I have spent a lot of time on this already but obviously I'm not on the
> right track. 

No, with little efforts what you did can be made to work. However, I'll
suggest a more orthogonal, easier to maintain, approach than the one you
have chosen.



> Can you suggest a different approach ?

This approach is based on the fact that, when an XSLT transform is about
to be performed, XXE first looks to see whether a
"command_containing_transform.transform" system property pointing to an
alternate XSLT style sheet has been defined. If this is the case
<transform> uses this alternate style sheet rather than the one
specified in  the "stylesheet" attribute of <transform>. This useful
feature is documented here:
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/transform.html#custom_xslt

Now we are going to slightly change your <command name="docb.kiesStijl">
to make it set system property "docb.toPS.transform" to a value based on
what the user has picked.

In order to do this, we'll invoke standard Java function
java.lang.System.setProperty in a <get> XPath-based construct. (Here the
<get> is just used for its side effect.) Invoking Java methods from
XPath expressions is documented here:
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/xpathextfunc_java.html

Please test this approach by doing this:

[1] Restore docbook/xslMenu.incl to its original state by removing *all*
your changes.

[2] replace:
---
<command name="docb.convertToPS">
  <macro>
    <sequence>
      <command name="selectConvertedFile"
               parameter="saveFileURLWithExtension=%0" />
      <command name="docb.toPSFile"
               parameter='"%0" "%1" "%2" "%3" "%_"' />
    </sequence>
  </macro>
</command>
---

by:
---
 <command name="docb.chooseStylesheet">
   <macro>
     <sequence>
       <command name="pick"
                parameter="'Please choose a stylesheet' true
                           'Stylesheet A'
                           'xsl/fo/docbookA.xsl'
                           'Stylesheet B'
                           'xsl/fo/docbookB.xsl'
                           'Normal Stylesheet'
                           'xsl/fo/docbook.xsl'" />

       <get expression="sys:setProperty('docb.toPS.transform', '%c/%_')"
            xmlns:sys="java:java.lang.System"/>
     </sequence>
   </macro>
 </command>

 <command name="docb.convertToPS">
   <macro>
     <sequence>
       <command name="docb.chooseStylesheet" />
       <command name="selectConvertedFile"
                parameter="saveFileURLWithExtension=%0" />
       <command name="docb.toPSFile"
                parameter='"%0" "%1" "%2" "%3" "%_"' />
     </sequence>
   </macro>
 </command>
---

Note that we didn't change anything in  <command name="docb.toPS">
(that's what I call this approach orthogonal.)

[3] Run "Convert to PDF" normally. Your pick list is displayed before
the URL chooser list. If you choose 'Stylesheet A' or 'Stylesheet B',
"Convert to PDF" will not work because there is no docbookA.xsl and
docbookB.xsl stylesheets. If you choose 'Normal Stylesheet', it will
work fine. In all cases, this shows you that this approach is OK.





Reply via email to