Re: saxon-help Digest, Vol 112, Issue 11

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: saxon-help Digest, Vol 112, Issue 11

Rudolf de Grijs
Thank you for your answer and making this option clear, Christophe. I will look into it.

Kind regards,
Rudolf

ing. Rudolf de Grijs
Consultant

Contactgegevens
Jan Leentvaarlaan 21 - 3065 DC Rotterdam

T. +31(0)10 235 10 57 E. [hidden email]
M. +31(0)6 476 51 370 W. www.inovita.nl


-----Oorspronkelijk bericht-----
Van: [hidden email] [[hidden email]]
Verzonden: Thursday, October 15, 2015 15:08
Aan: [hidden email]
Onderwerp: saxon-help Digest, Vol 112, Issue 11

Send saxon-help mailing list submissions to
[hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
https://lists.sourceforge.net/lists/listinfo/saxon-help
or, via email, send a message with subject or body 'help' to
[hidden email]

You can reach the person managing the list at
[hidden email]

When replying, please edit your Subject line so it is more specific than "Re: Contents of saxon-help digest..."


Today's Topics:

   1. Unable to pass parameter when chaining stylesheets
      (Rudolf de Grijs)
   2. Re: Unable to pass parameter when chaining stylesheets
      (Christophe Marchand)


----------------------------------------------------------------------

Message: 1
Date: Thu, 15 Oct 2015 12:23:48 +0000
From: Rudolf de Grijs <[hidden email]>
Subject: [saxon] Unable to pass parameter when chaining stylesheets
To: "'[hidden email]'"
<[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="us-ascii"

Is it possible to pass a parameter to a chained stylesheet?

I've created the following simple test case

xslt1 / not interested in the input to make it as simple as possible!
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:param name="contextPath"></xsl:param>
    <xsl:output method="xml"/>

    <xsl:template match="/">
        <first contextPath="{$contextPath}">
            First xslt template ..
        </first>
    </xsl:template>

</xsl:stylesheet>

xslt2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
   <xsl:param name="contextPath"></xsl:param>
   <xsl:output method="xml"/>

    <xsl:template match="/">
        <second contextPath="{$contextPath}">
            <xsl:copy>
                <xsl:apply-templates/>
            </xsl:copy>
        </second>
    </xsl:template>

    <xsl:template match="@* | node()">
        <xsl:copy>
                   <xsl:apply-templates select="@* | node()" />
                </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

Scenario 1 - run against 1 stylesheet
/** stf is SaxonTransformerFactory */
public void transformOne() throws TransformerConfigurationException, TransformerException {

        Transformer t = stf.newTransformer(loadSource("xslt1.xsl"));


        t.setParameter("contextPath", "/x/y/z");
        t.transform(loadSource("users.xml"), new StreamResult(System.out)); }

Result (which is ok!):
<?xml version="1.0" encoding="UTF-8"?><first contextPath="/x/y/z">
            First xslt template ..
</first>

And now chaining the two stylesheets
  public void transform() throws TransformerConfigurationException, TransformerException {
        TransformerHandler th1 = stf.newTransformerHandler(loadSource("xslt1.xsl"));
        TransformerHandler th2 = stf.newTransformerHandler(loadSource("xslt2.xsl"));


        /* setup XSLT pipeline */
        th1.setResult(new SAXResult(th2));
        th2.setResult(new StreamResult(System.out));
        Transformer t = stf.newTransformer();

        t.setParameter("contextPath", "/x/y/z");
        t.transform(loadSource("users.xml"), new SAXResult(th1));
    }

Result (can't get access to the parameter!):
<?xml version="1.0" encoding="UTF-8"?>
<second contextPath="">
<first contextPath="">
                First xslt template ..
        </first>
</second>

Any help would be appreciated.

Kind regards,
Ruud de Grijs

ing. Rudolf de Grijs
Consultant

Contactgegevens
Jan Leentvaarlaan 21 - 3065 DC Rotterdam

T. +31(0)10 235 10 57   E. [hidden email]<[hidden email]>
M. +31(0)6 476 51 370   W. www.inovita.nl<http://www.inovita.nl>

[http://www.inovita.nl/web/inovita_signature.jpg]

BTW Nummer: NL 8091.30.198.B.01 - KvK: 24305459

De informatie in dit e-mailbericht is vertrouwelijk en uitsluitend bestemd voor de geadresseerde. Wanneer u dit bericht per abuis ontvangt, verzoeken wij u contact op te nemen met de afzender per kerende e-mail. Verder verzoeken wij u in dat geval dit e-mailbericht te vernietigen en de inhoud ervan aan niemand openbaar te maken. Wij aanvaarden geen aansprakelijkheid voor onjuiste, onvolledige dan wel ontijdige overbrenging van de inhoud van een verzonden e-mailbericht, noch voor daarbij overgebrachte virussen.
-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

Message: 2
Date: Thu, 15 Oct 2015 14:49:25 +0200
From: Christophe Marchand <[hidden email]>
Subject: Re: [saxon] Unable to pass parameter when chaining
stylesheets
To: [hidden email]
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="windows-1252"

Parameters are XSL scoped. That means, you have to define the parameter value for each TransformerHandler you have in your pipe, if they need it
- you can give the parameter, either it's not expected.

I use such pipes, that chains the same XSL, but with different values for the same parameter, at each step of the pipe. Something like

<pipe>
   <xslt href="step.xsl">
     <param name="p" value="step1"/>
   </xslt>
   <xslt href="step.xsl">
     <param name="p" value="step2"/>
   </xslt>
</pipe>

This constructs a pipe, where source.xml is transformed by step.xsl with p="step1", then by step.xsl with p="step2"

Hope this helps,
Christophe

Le 15/10/2015 14:23, Rudolf de Grijs a ?crit :
>
> Is it possible to pass a parameter to a chained stylesheet?
>
> I?ve created the following simple test case
>
> xslt1 / not interested in the input to make it as simple as possible!
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="2.0">
>
> *<xsl:param name="contextPath"></xsl:param>*
>
>     <xsl:output method="xml"/>
>
>     <xsl:template match="/">
>
>         <first contextPath=*"{$contextPath}"*>
>
>             First xslt template ..
>
>         </first>
>
> </xsl:template>
>
> </xsl:stylesheet>
>
> xslt2
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="2.0">
>
> *   <xsl:param name="contextPath"></xsl:param>*
>
>    <xsl:output method="xml"/>
>
>     <xsl:template match="/">
>
>         <second contextPath=*"{$contextPath}"*>
>
> <xsl:copy>
>
> <xsl:apply-templates/>
>
> </xsl:copy>
>
>         </second>
>
> </xsl:template>
>
>     <xsl:template match="@* | node()">
>
>         <xsl:copy>
>
>    <xsl:apply-templates select="@* | node()" />
>
> </xsl:copy>
>
>     </xsl:template>
>
> </xsl:stylesheet>
>
> Scenario 1 ? run against 1 stylesheet
>
> /** stf is SaxonTransformerFactory */
>
> public void transformOne() throws TransformerConfigurationException,
> TransformerException {
>
>         Transformer t = stf.newTransformer(loadSource("xslt1.xsl"));
>
>         t.setParameter("contextPath", "/x/y/z");
>
> t.transform(loadSource("users.xml"), new StreamResult(System.out));
>
> }
>
> Result (which is ok!):
>
> <?xml version="1.0" encoding="UTF-8"?><first contextPath="/x/y/z">
>
>             First xslt template ..
>
> </first>
>
> And now chaining the two stylesheets
>
>   public void transform() throws TransformerConfigurationException,
> TransformerException {
>
> TransformerHandler th1 =
> stf.newTransformerHandler(loadSource("xslt1.xsl"));
>
> TransformerHandler th2 =
> stf.newTransformerHandler(loadSource("xslt2.xsl"));
>
>         /* setup XSLT pipeline */
>
> th1.setResult(new SAXResult(th2));
>
> th2.setResult(new StreamResult(System.out));
>
>         Transformer t = stf.newTransformer();
>
>         t.setParameter("contextPath", "/x/y/z");
>
> t.transform(loadSource("users.xml"), new SAXResult(th1));
>
>     }
>
> Result (can?t get access to the parameter!):
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <second contextPath="">
>
> <first contextPath="">
>
>                 First xslt template ..
>
>         </first>
>
> </second>
>
> Any help would be appreciated.
>
> Kind regards,
>
> Ruud de Grijs
>
> ing. Rudolf de Grijs
> Consultant
>
> *Contactgegevens
> *Jan Leentvaarlaan 21 - 3065 DC Rotterdam
>
> T. +31(0)10 235 10 57 E. [hidden email]
> <[hidden email]>
> M. +31(0)6 476 51 370 W. www.inovita.nl <http://www.inovita.nl>
>
>
>
> BTW Nummer: NL 8091.30.198.B.01 - KvK: 24305459
>
> De informatie in dit e-mailbericht is vertrouwelijk en uitsluitend
> bestemd voor de geadresseerde. Wanneer u dit bericht per abuis
> ontvangt, verzoeken wij u contact op te nemen met de afzender per
> kerende e-mail. Verder verzoeken wij u in dat geval dit e-mailbericht
> te vernietigen en de inhoud ervan aan niemand openbaar te maken. Wij
> aanvaarden geen aansprakelijkheid voor onjuiste, onvolledige dan wel
> ontijdige overbrenging van de inhoud van een verzonden e-mailbericht,
> noch voor daarbij overgebrachte virussen.
>
>
>
> ----------------------------------------------------------------------
> --------
>
>
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

------------------------------------------------------------------------------


------------------------------

_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
The saxon-help list is archived at http://saxon.markmail.org/

End of saxon-help Digest, Vol 112, Issue 11
*******************************************

------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help