setvalue in PFC causes instance tags to disappear

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

setvalue in PFC causes instance tags to disappear

Mark Gibson-2
Hello,
I've just started using PresentationServer to attempt to re-implement our
website, and am finding it very useful and fairly easy.

Except for one problem with populating of instance data from URL parameters
using <setvalue> in the page-flow.xml.

In page-flow.xml:

<page path-info="/test-submission"
      default-submission="/default-submission.xml"
      view="/copy.xsl">
  <setvalue ref="/form/search/simple" parameter="simple"/>
  <setvalue ref="/form/search/page" parameter="page"/>
  <setvalue ref="/form/search/page-size" parameter="page-size"/>
  <setvalue ref="/form/search/sort" parameter="sort"/>
</page>

In default-submission.xml:

<form>
  <branch>0</branch>
  <search>
    <simple/>
    <page>1</page>
    <page-size>20</page-size>
    <sort>offer-price</sort>
  </search>
</form>

In copy.xsl:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:copy-of select="doc('input:instance')"/>
  </xsl:template>
</xsl:stylesheet>

When I visit /test-submission without any URL parameters, I get:

<form>
  <branch>0</branch>
  <search>

        1
        20
        offer-price
  </search>
</form>

Notice the missing tags!

But, if I provide params: /test-submission?simple=hello&page=2&page-size=50
I get:

<form>
  <branch>0</branch>
  <search>
    <simple>hello</simple>
    <page>2</page>
    <page-size>50</page-size>
    offer-price
  </search>
</form>

The tags reappear for the supplied params!

Is this a bug, or am I missing something?

(I'm using ops-3.0.0.200601132127, Tomcat 5.5.12, JDK 1.5.0-06, Linux)

Thanks
- Mark Gibson



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: setvalue in PFC causes instance tags to disappear

Mark Gibson-2
I'm sorry to press the issue, especially being new around here,
but does anyone have any idea why I'm getting the following problems.
It's really causing me a headache, as i'm having to work around it
using XUpdate and overly complicated pipelines (using oxf:request).

[hidden email] wrote:

> Hello,
> I've just started using PresentationServer to attempt to re-implement our
> website, and am finding it very useful and fairly easy.
>
> Except for one problem with populating of instance data from URL parameters
> using <setvalue> in the page-flow.xml.
>
> In page-flow.xml:
>
> <page path-info="/test-submission"
>       default-submission="/default-submission.xml"
>       view="/copy.xsl">
>   <setvalue ref="/form/search/simple" parameter="simple"/>
>   <setvalue ref="/form/search/page" parameter="page"/>
>   <setvalue ref="/form/search/page-size" parameter="page-size"/>
>   <setvalue ref="/form/search/sort" parameter="sort"/>
> </page>
>
> In default-submission.xml:
>
> <form>
>   <search>
>     <simple/>
>     <page>1</page>
>     <page-size>20</page-size>
>     <sort>offer-price</sort>
>   </search>
> </form>
>
> In copy.xsl:
>
> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:template match="/">
>     <xsl:copy-of select="doc('input:instance')"/>
>   </xsl:template>
> </xsl:stylesheet>
>
> When I visit /test-submission without any URL parameters, I get:
>
> <form>
>   <search>
>
> 1
> 20
> offer-price
>   </search>
> </form>
>
> Notice the missing tags!
>
> But, if I provide params: /test-submission?simple=hello&page=2&page-size=50
> I get:
>
> <form>
>   <search>
>     <simple>hello</simple>
>     <page>2</page>
>     <page-size>50</page-size>
>     offer-price
>   </search>
> </form>
>
> The tags reappear for the supplied params!
>
> Is this a bug, or am I missing something?
>
> (I'm using ops-3.0.0.200601132127, Tomcat 5.5.12, JDK 1.5.0-06, Linux)
>
> Thanks
> - Mark Gibson
--
Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk>
Web Developer & Database Admin
Cromwell Tools Ltd.
Leicester, England.

___________________________________________________
 
This email is intended for the named recipient. The information contained
in it is confidential.  You should not copy it for any purposes, nor
disclose its contents to any other party.  If you received this email
in error, please notify the sender immediately via email, and delete it from
your computer.
 
Any views or opinions presented are solely those of the author and do not
necessarily represent those of the company.
 
Registered Office: PO Box 14, Chartwell Dr, Wigston, Leicester. LE18 1AT
__________________________________________________




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: setvalue in PFC causes instance tags to disappear

Erik Bruchez
Administrator
In reply to this post by Mark Gibson-2
Mark,

It looks like you hit a but (a couple of missing xsl:copy...). Try the
attached file to replace ops/pfc/setvalue-extract.xsl.

-Erik

[hidden email] wrote:

> Hello,
> I've just started using PresentationServer to attempt to re-implement our
> website, and am finding it very useful and fairly easy.
>
> Except for one problem with populating of instance data from URL parameters
> using <setvalue> in the page-flow.xml.
>
> In page-flow.xml:
>
> <page path-info="/test-submission"
>       default-submission="/default-submission.xml"
>       view="/copy.xsl">
>   <setvalue ref="/form/search/simple" parameter="simple"/>
>   <setvalue ref="/form/search/page" parameter="page"/>
>   <setvalue ref="/form/search/page-size" parameter="page-size"/>
>   <setvalue ref="/form/search/sort" parameter="sort"/>
> </page>
>
> In default-submission.xml:
>
> <form>
>   <branch>0</branch>
>   <search>
>     <simple/>
>     <page>1</page>
>     <page-size>20</page-size>
>     <sort>offer-price</sort>
>   </search>
> </form>
>
> In copy.xsl:
>
> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:template match="/">
>     <xsl:copy-of select="doc('input:instance')"/>
>   </xsl:template>
> </xsl:stylesheet>
>
> When I visit /test-submission without any URL parameters, I get:
>
> <form>
>   <branch>0</branch>
>   <search>
>
> 1
> 20
> offer-price
>   </search>
> </form>
>
> Notice the missing tags!
>
> But, if I provide params: /test-submission?simple=hello&page=2&page-size=50
> I get:
>
> <form>
>   <branch>0</branch>
>   <search>
>     <simple>hello</simple>
>     <page>2</page>
>     <page-size>50</page-size>
>     offer-price
>   </search>
> </form>
>
> The tags reappear for the supplied params!
>
> Is this a bug, or am I missing something?
>
> (I'm using ops-3.0.0.200601132127, Tomcat 5.5.12, JDK 1.5.0-06, Linux)
>
> Thanks
> - Mark Gibson
>
>
>
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

<!--
    Copyright (C) 2005 Orbeon, Inc.

    This program is free software; you can redistribute it and/or modify it under the terms of the
    GNU Lesser General Public License as published by the Free Software Foundation; either version
    2.1 of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU Lesser General Public License for more details.

    The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
-->
<xsl:stylesheet version="2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:c="http://www.orbeon.com/oxf/controller"
    xmlns:function="http://www.orbeon.com/xslt-function">

    <xsl:import href="oxf:/oxf/xslt/utils/copy.xsl"/>
    <xsl:import href="oxf:/oxf/xslt/utils/evaluate.xsl"/>

    <!-- Inputs -->
    <xsl:variable name="instance" select="/" as="document-node()"/>
    <xsl:variable name="setvalues" select="doc('input:setvalues')/*/(c:param | c:setvalue)" as="element()*"/>
    <xsl:variable name="matcher-results" select="doc('input:matcher-result')/*/group" as="element()*"/>
    <xsl:variable name="request-info" select="doc('input:request-info')/*" as="element()"/>

    <!-- Nodes pointed to by setvalues -->
    <!-- FIXME: Somehow we get a list of nodes from function:evaluate(); the last one appears to be the one we are looking for -->
    <xsl:variable name="param-nodes" as="node()*"
                  select="for $i in $setvalues return function:evaluate($instance, $i/@ref, $i/namespace::node())[last()]"/>

    <xsl:variable name="param-nodes-ids" as="xs:string*"
                  select="for $i in $param-nodes return generate-id($i)"/>

    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>

    <!-- Case of element -->
    <xsl:template match="*[generate-id() = $param-nodes-ids]">
        <xsl:variable name="value" select="function:getvalue(.)" as="xs:string?"/>
        <xsl:choose>
            <xsl:when test="$value">
                <xsl:copy>
                    <xsl:copy-of select="@*"/>
                    <xsl:value-of select="$value"/>
                </xsl:copy>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy>
                    <xsl:apply-templates/>
                </xsl:copy>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <!-- Case of attribute -->
    <xsl:template match="@*[generate-id() = $param-nodes-ids]">
        <xsl:variable name="value" select="function:getvalue(.)" as="xs:string?"/>
        <xsl:choose>
            <xsl:when test="$value">
                <xsl:attribute name="{name()}">
                    <xsl:value-of select="$value"/>
                </xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy>
                    <xsl:apply-templates/>
                </xsl:copy>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:function name="function:getvalue" as="xs:string?">
        <xsl:param name="current" as="item()"/><!-- element or attribute -->
        <xsl:variable name="param-index" select="index-of($param-nodes-ids, generate-id($current))" as="xs:integer"/>

        <xsl:choose>
            <xsl:when test="$setvalues[$param-index]/@parameter">
                <!-- Parameter name -->
                <xsl:variable name="parameter" select="$request-info/parameters/parameter[name = $setvalues[$param-index]/@parameter]" as="element()?"/>
                <xsl:choose>
                    <!-- Set the value only if the parameter is present -->
                    <xsl:when test="$parameter">
                        <xsl:value-of select="string-join($parameter/value, ' ')"/>
                    </xsl:when>
                    <!-- Otherwise just leave whatever was there -->
                    <xsl:otherwise>
                        <xsl:copy-of select="()"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:when test="$setvalues[$param-index]/@matcher-group">
                <!-- Matcher group index -->
                <xsl:value-of select="$matcher-results[xs:integer($setvalues[$param-index]/@matcher-group)]"/>
            </xsl:when>
            <xsl:otherwise>
                <!-- Backward compatibility mode -->
                <xsl:value-of select="$matcher-results[$param-index]"/>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:function>

</xsl:stylesheet>


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: setvalue in PFC causes instance tags to disappear

Mark Gibson-2
Erik Bruchez wrote:
> Mark,
>
> It looks like you hit a but (a couple of missing xsl:copy...). Try the
> attached file to replace ops/pfc/setvalue-extract.xsl.
>
> -Erik

Works perfectly, thanks very much.

I'd attempted implementing an XML pipelining language in PHP5, until I
found PresentationServer, and so far it's been great, so I've given up
on my own attempts.

Thanks for such a great product.
--
Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk>
Web Developer & Database Admin
Cromwell Tools Ltd.
Leicester, England.

___________________________________________________
 
This email is intended for the named recipient. The information contained
in it is confidential.  You should not copy it for any purposes, nor
disclose its contents to any other party.  If you received this email
in error, please notify the sender immediately via email, and delete it from
your computer.
 
Any views or opinions presented are solely those of the author and do not
necessarily represent those of the company.
 
Registered Office: PO Box 14, Chartwell Dr, Wigston, Leicester. LE18 1AT
__________________________________________________




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: setvalue in PFC causes instance tags to disappear

Erik Bruchez
Administrator
Mark Gibson wrote:

> Erik Bruchez wrote:
>> Mark,
>>
>> It looks like you hit a but (a couple of missing xsl:copy...). Try the
>> attached file to replace ops/pfc/setvalue-extract.xsl.
>>
>> -Erik
>
> Works perfectly, thanks very much.
>
> I'd attempted implementing an XML pipelining language in PHP5, until I
> found PresentationServer, and so far it's been great, so I've given up
> on my own attempts.
>
> Thanks for such a great product.
Thanks!

-Erik




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws