Inserting HTML from an instance into a page

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

Inserting HTML from an instance into a page

Stephen Bayliss

I managed to succeed in inserting XHTML, from an instance, into a page, by using the following technique:

 

  • Pipeline service call through an xforms:submission and page flow to populate a node in my instance document with the XHTML to be inserted (this through some oxf:xslt to actually produce the XHTML)
  • Xforms:bind with a calculate attribute, which uses saxon:serialize to produce the serialized HTML, to another instance
  • Xforms:output control bound to this second instance document

 

The purpose of this was to produce an XHTML-styled presentation of some XML data.

 

However, the process seems very sensitive to namespaces:  The only way I could get it working is to ensure that xhtml is defined as the default namespace in the XSL that creates the XHTML (ie none of the tags actually specify the xhtml: namespace prefix).  Additionally, extra namespace definitions may get inserted through the XSL and pipeline processing; to prevent these appearing in my instance node I found it necessary to declare them at the start of the instance.

 

Without doing this I got errors like this in the browser:

org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes must be created before the children of an element node when evaluating 'saxon:serialize(instance('instance')/formattedMetadataRecord/xhtml:div , 'html')'

 

Presumably this is because the DOM is constructed by client-side javascript, and the javascript is doing simple text processing, and therefore having problems with namespace prefixes, or something like this?

 

I can mock up an example of this if necessary.

 

Steve

 



--
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: Inserting HTML from an instance into a page

Erik Bruchez
Administrator
Stephen Bayliss wrote:
 > I managed to succeed in inserting XHTML, from an instance, into a page,
 > by using the following technique:
 >
 >     * Pipeline service call through an xforms:submission and page flow
 >       to populate a node in my instance document with the XHTML to be
 >       inserted (this through some oxf:xslt to actually produce the XHTML)
 >     * Xforms:bind with a calculate attribute, which uses saxon:serialize
 >       to produce the serialized HTML, to another instance
 >     * Xforms:output control bound to this second instance document
 >
 > The purpose of this was to produce an XHTML-styled presentation of some
 > XML data.
 >
 > However, the process seems very sensitive to namespaces: The only
 > way I could get it working is to ensure that xhtml is defined as the
 > default namespace in the XSL that creates the XHTML (ie none of the
 > tags actually specify the xhtml: namespace prefix).  Additionally,
 > extra namespace definitions may get inserted through the XSL and
 > pipeline processing; to prevent these appearing in my instance node
 > I found it necessary to declare them at the start of the instance.
 >
 > Without doing this I got errors like this in the browser:
 >
 > org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes must
 > be created before the children of an element node when evaluating
 > 'saxon:serialize(instance('instance')/formattedMetadataRecord/xhtml:div
 > , 'html')'
 >
 > Presumably this is because the DOM is constructed by client-side
 > javascript, and the javascript is doing simple text processing, and
 > therefore having problems with namespace prefixes, or something like
 > this?

OPS doesn't do any client-side DOM manipulations related to XForms
instances (only some related to the HTML DOM for displaying controls),
so that would not be the right explanation ;-)

 > I can mock up an example of this if necessary.

Sure. Try also to serialize to text directly from XPL, and return a
serialized string with the response of the submission. That's what we
do, the the help of the HTML formatter, to display in HTML the content
of XForms instances in examples such as "XForms Controls" and "Wizard
with Switch".

-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
Reply | Threaded
Open this post in threaded view
|

RE: Inserting HTML from an instance into a page

Stephen Bayliss
In reply to this post by Stephen Bayliss
Hi Erik

It was the "XForms Controls" and "Wizard with Switch" examples that I
followed.

Here's a mocked up example.  Just a single "view" file, called from the
following page flow:
    <page id="example-html" path-info="/example-html"
view="/example-html/view.xhtml"/>

I've pasted the whole view.xhtml below.

There are three different example instance nodes used to show the
different behaviours that seem anomalous.

You can see the different behaviours by changing the calculate attribute
of the <xforms:bind> to reference the different instance nodes.

1. xhtml as default namespace
calculate="saxon:serialize(instance('instance')/formatted/xhtml:div ,
'html')"

This example renders fine

2. xhtml: used as namespace prefix for the xhtml tags
calculate="saxon:serialize(instance('instance')/formatted1/xhtml:div ,
'html')"

This does not render correctly even though it's valid xhtml; it's as if
the xhtml tags have not been recognised, so just literal text has been
output.

3. xhtml as default namespace; additional namespace declared as well
calculate="saxon:serialize(instance('instance')/formatted2/xhtml:div ,
'html')"

This produces an error even though it's valid xml:
org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes must be
created before the children of an element node when evaluating
'saxon:serialize(instance('instance')/formatted2/xhtml:div , 'html')'

Steve

------------------------
/example-html/view.xhtml
------------------------
<xhtml:html
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">
    <xhtml:head>
        <xhtml:title>Example - XHTML instance</xhtml:title>
        <xforms:model>
            <xforms:instance id="instance">
                <instance>
                    <!-- xhtml as default namespace: correctly rendered
-->
                    <formatted>
                        <div xmlns="http://www.w3.org/1999/xhtml">
                            <table>
                                <tr>
                                    <td><strong>Column 1</strong></td>
                                    <td><strong>Column 2</strong></td>
                                </tr>
                                <tr>
                                    <td>Column 1</td>
                                    <td>Column 2</td>
                                </tr>
                                <tr>
                                    <td>Column 1</td>
                                    <td>Column 2</td>
                                </tr>
                            </table>
                        </div>
                    </formatted>
                    <!-- xhtml tags use xhtml namespace prefix:
incorrectly rendered -->
                    <formatted1>
                        <xhtml:div>
                            <xhtml:table>
                                <xhtml:tr>
                                    <xhtml:td><xhtml:strong>Column
1</xhtml:strong></xhtml:td>
                                    <xhtml:td><xhtml:strong>Column
2</xhtml:strong></xhtml:td>
                                </xhtml:tr>
                                <xhtml:tr>
                                    <xhtml:td>Column 1</xhtml:td>
                                    <xhtml:td>Column 2</xhtml:td>
                                </xhtml:tr>
                                <xhtml:tr>
                                    <xhtml:td>Column 1</xhtml:td>
                                    <xhtml:td>Column 2</xhtml:td>
                                </xhtml:tr>
                            </xhtml:table>
                        </xhtml:div>
                    </formatted1>
                    <!-- xhtml as default namespace; additional
namespace declared, causes error -->
                    <formatted2>
                        <div xmlns="http://www.w3.org/1999/xhtml"
xmlns:example="http://nothing.here">
                            <table>
                                <tr>
                                    <td><strong>Column 1</strong></td>
                                    <td><strong>Column 2</strong></td>
                                </tr>
                                <tr>
                                    <td>Column 1</td>
                                    <td>Column 2</td>
                                </tr>
                                <tr>
                                    <td>Column 1</td>
                                    <td>Column 2</td>
                                </tr>
                            </table>
                        </div>
                    </formatted2>
                </instance>  
            </xforms:instance>

            <!-- instance to hold the serialised xhtml -->
            <xforms:instance id="styled-formatted">
                <xhtml:div/>
            </xforms:instance>
           
            <!-- binding to serialise instance xhtml node -->
            <!-- change /formatted/ to /formatted1/, /formatted2/ in the
                "calculate" attribute to show different behaviours -->
            <xforms:bind nodeset="instance('styled-formatted')"
 
calculate="saxon:serialize(instance('instance')/formatted/xhtml:div ,
'html')"/>
            </xforms:model>
        </xhtml:head>

    <xhtml:body>
        <xhtml:h1>Example XHTML instance</xhtml:h1>
        <xhtml:fieldset>
            <xhtml:legend>XHTML</xhtml:legend>
                <xforms:output ref="instance('styled-formatted')"
appearance="xxforms:html"  />
        </xhtml:fieldset>
    </xhtml:body>
</xhtml:html>






-----Original Message-----
From: Erik Bruchez [mailto:[hidden email]] On Behalf Of Erik Bruchez
Sent: 25 November 2005 14:23
To: [hidden email]
Subject: Re: [ops-users] Inserting HTML from an instance into a page

Stephen Bayliss wrote:
 > I managed to succeed in inserting XHTML, from an instance, into a
page,
 > by using the following technique:
 >
 >     * Pipeline service call through an xforms:submission and page
flow
 >       to populate a node in my instance document with the XHTML to be
 >       inserted (this through some oxf:xslt to actually produce the
XHTML)
 >     * Xforms:bind with a calculate attribute, which uses
saxon:serialize
 >       to produce the serialized HTML, to another instance
 >     * Xforms:output control bound to this second instance document
 >
 > The purpose of this was to produce an XHTML-styled presentation of
some
 > XML data.
 >
 > However, the process seems very sensitive to namespaces: The only
 > way I could get it working is to ensure that xhtml is defined as the
 > default namespace in the XSL that creates the XHTML (ie none of the
 > tags actually specify the xhtml: namespace prefix).  Additionally,
 > extra namespace definitions may get inserted through the XSL and
 > pipeline processing; to prevent these appearing in my instance node
 > I found it necessary to declare them at the start of the instance.
 >
 > Without doing this I got errors like this in the browser:
 >
 > org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes must
 > be created before the children of an element node when evaluating
 >
'saxon:serialize(instance('instance')/formattedMetadataRecord/xhtml:div
 > , 'html')'
 >
 > Presumably this is because the DOM is constructed by client-side
 > javascript, and the javascript is doing simple text processing, and
 > therefore having problems with namespace prefixes, or something like
 > this?

OPS doesn't do any client-side DOM manipulations related to XForms
instances (only some related to the HTML DOM for displaying controls),
so that would not be the right explanation ;-)

 > I can mock up an example of this if necessary.

Sure. Try also to serialize to text directly from XPL, and return a
serialized string with the response of the submission. That's what we
do, the the help of the HTML formatter, to display in HTML the content
of XForms instances in examples such as "XForms Controls" and "Wizard
with Switch".

-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
Reply | Threaded
Open this post in threaded view
|

Re: Inserting HTML from an instance into a page

Alessandro  Vernet
Administrator
Hi Stephen,

I modified the example you sent to add an <xforms:output> without the
HTML appearance, so we can see what is returned by the
saxon:serialize() function. Looking at the cases you mention in your
email:

1) Exactly what you typed is returned:

<div xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns="http://www.w3.org/1999/xhtml"> <table> <tr> <td> <strong>Column
1</strong> </td> <td> <strong>Column 2</strong> </td> </tr> <tr>
<td>Column 1</td> <td>Column 2</td> </tr> <tr> <td>Column 1</td>
<td>Column 2</td> </tr> </table> </div>

This works, as there is no prefix on the HTML elements.

2) In the second case you get as well exactly what you typed:

<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:xforms="http://www.w3.org/2002/xforms"> <xhtml:table> <xhtml:tr>
<xhtml:td> <xhtml:strong>Column 1 </xhtml:strong> </xhtml:td>
<xhtml:td> <xhtml:strong>Column 2 </xhtml:strong> </xhtml:td>
</xhtml:tr> <xhtml:tr> <xhtml:td>Column 1</xhtml:td> <xhtml:td>Column
2</xhtml:td> </xhtml:tr> <xhtml:tr> <xhtml:td>Column 1</xhtml:td>
<xhtml:td>Column 2</xhtml:td> </xhtml:tr> </xhtml:table> </xhtml:div>

That does not work, even on Firefox. I guess the browser doesn't like
the prefixes there.

3) In the third case, Saxon throws an exception.

Now for this to work, you obviously need return elements without
prefixes. So only the first method works. Is there a way to tell the
saxon:serialize() function to remove the prefixes (for the second
case)? Why is saxon:serialize() throwing an exception in the third
case? I don't have an answer to those questions, and if I were you, I
would ask them in the Saxon mailing list.

I have also attached your test case, just slightly modified so it
works on the XForms sandbox.

Alex

On 11/28/05, Stephen Bayliss <[hidden email]> wrote:

> Hi Erik
>
> It was the "XForms Controls" and "Wizard with Switch" examples that I
> followed.
>
> Here's a mocked up example.  Just a single "view" file, called from the
> following page flow:
>     <page id="example-html" path-info="/example-html"
> view="/example-html/view.xhtml"/>
>
> I've pasted the whole view.xhtml below.
>
> There are three different example instance nodes used to show the
> different behaviours that seem anomalous.
>
> You can see the different behaviours by changing the calculate attribute
> of the <xforms:bind> to reference the different instance nodes.
>
> 1. xhtml as default namespace
> calculate="saxon:serialize(instance('instance')/formatted/xhtml:div ,
> 'html')"
>
> This example renders fine
>
> 2. xhtml: used as namespace prefix for the xhtml tags
> calculate="saxon:serialize(instance('instance')/formatted1/xhtml:div ,
> 'html')"
>
> This does not render correctly even though it's valid xhtml; it's as if
> the xhtml tags have not been recognised, so just literal text has been
> output.
>
> 3. xhtml as default namespace; additional namespace declared as well
> calculate="saxon:serialize(instance('instance')/formatted2/xhtml:div ,
> 'html')"
>
> This produces an error even though it's valid xml:
> org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes must be
> created before the children of an element node when evaluating
> 'saxon:serialize(instance('instance')/formatted2/xhtml:div , 'html')'
>
> Steve
>
> ------------------------
> /example-html/view.xhtml
> ------------------------
> <xhtml:html
>     xmlns:xhtml="http://www.w3.org/1999/xhtml"
>     xmlns:xforms="http://www.w3.org/2002/xforms"
>     xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">
>     <xhtml:head>
>         <xhtml:title>Example - XHTML instance</xhtml:title>
>         <xforms:model>
>             <xforms:instance id="instance">
>                 <instance>
>                     <!-- xhtml as default namespace: correctly rendered
> -->
>                     <formatted>
>                         <div xmlns="http://www.w3.org/1999/xhtml">
>                             <table>
>                                 <tr>
>                                     <td><strong>Column 1</strong></td>
>                                     <td><strong>Column 2</strong></td>
>                                 </tr>
>                                 <tr>
>                                     <td>Column 1</td>
>                                     <td>Column 2</td>
>                                 </tr>
>                                 <tr>
>                                     <td>Column 1</td>
>                                     <td>Column 2</td>
>                                 </tr>
>                             </table>
>                         </div>
>                     </formatted>
>                     <!-- xhtml tags use xhtml namespace prefix:
> incorrectly rendered -->
>                     <formatted1>
>                         <xhtml:div>
>                             <xhtml:table>
>                                 <xhtml:tr>
>                                     <xhtml:td><xhtml:strong>Column
> 1</xhtml:strong></xhtml:td>
>                                     <xhtml:td><xhtml:strong>Column
> 2</xhtml:strong></xhtml:td>
>                                 </xhtml:tr>
>                                 <xhtml:tr>
>                                     <xhtml:td>Column 1</xhtml:td>
>                                     <xhtml:td>Column 2</xhtml:td>
>                                 </xhtml:tr>
>                                 <xhtml:tr>
>                                     <xhtml:td>Column 1</xhtml:td>
>                                     <xhtml:td>Column 2</xhtml:td>
>                                 </xhtml:tr>
>                             </xhtml:table>
>                         </xhtml:div>
>                     </formatted1>
>                     <!-- xhtml as default namespace; additional
> namespace declared, causes error -->
>                     <formatted2>
>                         <div xmlns="http://www.w3.org/1999/xhtml"
> xmlns:example="http://nothing.here">
>                             <table>
>                                 <tr>
>                                     <td><strong>Column 1</strong></td>
>                                     <td><strong>Column 2</strong></td>
>                                 </tr>
>                                 <tr>
>                                     <td>Column 1</td>
>                                     <td>Column 2</td>
>                                 </tr>
>                                 <tr>
>                                     <td>Column 1</td>
>                                     <td>Column 2</td>
>                                 </tr>
>                             </table>
>                         </div>
>                     </formatted2>
>                 </instance>
>             </xforms:instance>
>
>             <!-- instance to hold the serialised xhtml -->
>             <xforms:instance id="styled-formatted">
>                 <xhtml:div/>
>             </xforms:instance>
>
>             <!-- binding to serialise instance xhtml node -->
>             <!-- change /formatted/ to /formatted1/, /formatted2/ in the
>                 "calculate" attribute to show different behaviours -->
>             <xforms:bind nodeset="instance('styled-formatted')"
>
> calculate="saxon:serialize(instance('instance')/formatted/xhtml:div ,
> 'html')"/>
>             </xforms:model>
>         </xhtml:head>
>
>     <xhtml:body>
>         <xhtml:h1>Example XHTML instance</xhtml:h1>
>         <xhtml:fieldset>
>             <xhtml:legend>XHTML</xhtml:legend>
>                 <xforms:output ref="instance('styled-formatted')"
> appearance="xxforms:html"  />
>         </xhtml:fieldset>
>     </xhtml:body>
> </xhtml:html>
>
>
>
>
>
>
> -----Original Message-----
> From: Erik Bruchez [mailto:[hidden email]] On Behalf Of Erik Bruchez
> Sent: 25 November 2005 14:23
> To: [hidden email]
> Subject: Re: [ops-users] Inserting HTML from an instance into a page
>
> Stephen Bayliss wrote:
>  > I managed to succeed in inserting XHTML, from an instance, into a
> page,
>  > by using the following technique:
>  >
>  >     * Pipeline service call through an xforms:submission and page
> flow
>  >       to populate a node in my instance document with the XHTML to be
>  >       inserted (this through some oxf:xslt to actually produce the
> XHTML)
>  >     * Xforms:bind with a calculate attribute, which uses
> saxon:serialize
>  >       to produce the serialized HTML, to another instance
>  >     * Xforms:output control bound to this second instance document
>  >
>  > The purpose of this was to produce an XHTML-styled presentation of
> some
>  > XML data.
>  >
>  > However, the process seems very sensitive to namespaces: The only
>  > way I could get it working is to ensure that xhtml is defined as the
>  > default namespace in the XSL that creates the XHTML (ie none of the
>  > tags actually specify the xhtml: namespace prefix).  Additionally,
>  > extra namespace definitions may get inserted through the XSL and
>  > pipeline processing; to prevent these appearing in my instance node
>  > I found it necessary to declare them at the start of the instance.
>  >
>  > Without doing this I got errors like this in the browser:
>  >
>  > org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes must
>  > be created before the children of an element node when evaluating
>  >
> 'saxon:serialize(instance('instance')/formattedMetadataRecord/xhtml:div
>  > , 'html')'
>  >
>  > Presumably this is because the DOM is constructed by client-side
>  > javascript, and the javascript is doing simple text processing, and
>  > therefore having problems with namespace prefixes, or something like
>  > this?
>
> OPS doesn't do any client-side DOM manipulations related to XForms
> instances (only some related to the HTML DOM for displaying controls),
> so that would not be the right explanation ;-)
>
>  > I can mock up an example of this if necessary.
>
> Sure. Try also to serialize to text directly from XPL, and return a
> serialized string with the response of the submission. That's what we
> do, the the help of the HTML formatter, to display in HTML the content
> of XForms instances in examples such as "XForms Controls" and "Wizard
> with Switch".
>
> -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
>
>
>

--
Blog (XML, Web apps, Open Source): http://www.orbeon.com/blog/


--
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

rightcom.xhtml (4K) Download Attachment
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

RE: Inserting HTML from an instance into a page

Stephen Bayliss
In reply to this post by Stephen Bayliss
Alex

Thanks for that -- I agree, it does seem to be a Saxon issue, best
directed at their mailing lists.

Steve

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of
Alessandro Vernet
Sent: 01 December 2005 23:04
To: [hidden email]
Subject: Re: [ops-users] Inserting HTML from an instance into a page

Hi Stephen,

I modified the example you sent to add an <xforms:output> without the
HTML appearance, so we can see what is returned by the
saxon:serialize() function. Looking at the cases you mention in your
email:

1) Exactly what you typed is returned:

<div xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns="http://www.w3.org/1999/xhtml"> <table> <tr> <td> <strong>Column
1</strong> </td> <td> <strong>Column 2</strong> </td> </tr> <tr>
<td>Column 1</td> <td>Column 2</td> </tr> <tr> <td>Column 1</td>
<td>Column 2</td> </tr> </table> </div>

This works, as there is no prefix on the HTML elements.

2) In the second case you get as well exactly what you typed:

<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:xforms="http://www.w3.org/2002/xforms"> <xhtml:table> <xhtml:tr>
<xhtml:td> <xhtml:strong>Column 1 </xhtml:strong> </xhtml:td>
<xhtml:td> <xhtml:strong>Column 2 </xhtml:strong> </xhtml:td>
</xhtml:tr> <xhtml:tr> <xhtml:td>Column 1</xhtml:td> <xhtml:td>Column
2</xhtml:td> </xhtml:tr> <xhtml:tr> <xhtml:td>Column 1</xhtml:td>
<xhtml:td>Column 2</xhtml:td> </xhtml:tr> </xhtml:table> </xhtml:div>

That does not work, even on Firefox. I guess the browser doesn't like
the prefixes there.

3) In the third case, Saxon throws an exception.

Now for this to work, you obviously need return elements without
prefixes. So only the first method works. Is there a way to tell the
saxon:serialize() function to remove the prefixes (for the second
case)? Why is saxon:serialize() throwing an exception in the third
case? I don't have an answer to those questions, and if I were you, I
would ask them in the Saxon mailing list.

I have also attached your test case, just slightly modified so it
works on the XForms sandbox.

Alex

On 11/28/05, Stephen Bayliss <[hidden email]> wrote:
> Hi Erik
>
> It was the "XForms Controls" and "Wizard with Switch" examples that I
> followed.
>
> Here's a mocked up example.  Just a single "view" file, called from
the

> following page flow:
>     <page id="example-html" path-info="/example-html"
> view="/example-html/view.xhtml"/>
>
> I've pasted the whole view.xhtml below.
>
> There are three different example instance nodes used to show the
> different behaviours that seem anomalous.
>
> You can see the different behaviours by changing the calculate
attribute

> of the <xforms:bind> to reference the different instance nodes.
>
> 1. xhtml as default namespace
> calculate="saxon:serialize(instance('instance')/formatted/xhtml:div ,
> 'html')"
>
> This example renders fine
>
> 2. xhtml: used as namespace prefix for the xhtml tags
> calculate="saxon:serialize(instance('instance')/formatted1/xhtml:div ,
> 'html')"
>
> This does not render correctly even though it's valid xhtml; it's as
if
> the xhtml tags have not been recognised, so just literal text has been
> output.
>
> 3. xhtml as default namespace; additional namespace declared as well
> calculate="saxon:serialize(instance('instance')/formatted2/xhtml:div ,
> 'html')"
>
> This produces an error even though it's valid xml:
> org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes must
be

> created before the children of an element node when evaluating
> 'saxon:serialize(instance('instance')/formatted2/xhtml:div , 'html')'
>
> Steve
>
> ------------------------
> /example-html/view.xhtml
> ------------------------
> <xhtml:html
>     xmlns:xhtml="http://www.w3.org/1999/xhtml"
>     xmlns:xforms="http://www.w3.org/2002/xforms"
>     xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">
>     <xhtml:head>
>         <xhtml:title>Example - XHTML instance</xhtml:title>
>         <xforms:model>
>             <xforms:instance id="instance">
>                 <instance>
>                     <!-- xhtml as default namespace: correctly
rendered

> -->
>                     <formatted>
>                         <div xmlns="http://www.w3.org/1999/xhtml">
>                             <table>
>                                 <tr>
>                                     <td><strong>Column 1</strong></td>
>                                     <td><strong>Column 2</strong></td>
>                                 </tr>
>                                 <tr>
>                                     <td>Column 1</td>
>                                     <td>Column 2</td>
>                                 </tr>
>                                 <tr>
>                                     <td>Column 1</td>
>                                     <td>Column 2</td>
>                                 </tr>
>                             </table>
>                         </div>
>                     </formatted>
>                     <!-- xhtml tags use xhtml namespace prefix:
> incorrectly rendered -->
>                     <formatted1>
>                         <xhtml:div>
>                             <xhtml:table>
>                                 <xhtml:tr>
>                                     <xhtml:td><xhtml:strong>Column
> 1</xhtml:strong></xhtml:td>
>                                     <xhtml:td><xhtml:strong>Column
> 2</xhtml:strong></xhtml:td>
>                                 </xhtml:tr>
>                                 <xhtml:tr>
>                                     <xhtml:td>Column 1</xhtml:td>
>                                     <xhtml:td>Column 2</xhtml:td>
>                                 </xhtml:tr>
>                                 <xhtml:tr>
>                                     <xhtml:td>Column 1</xhtml:td>
>                                     <xhtml:td>Column 2</xhtml:td>
>                                 </xhtml:tr>
>                             </xhtml:table>
>                         </xhtml:div>
>                     </formatted1>
>                     <!-- xhtml as default namespace; additional
> namespace declared, causes error -->
>                     <formatted2>
>                         <div xmlns="http://www.w3.org/1999/xhtml"
> xmlns:example="http://nothing.here">
>                             <table>
>                                 <tr>
>                                     <td><strong>Column 1</strong></td>
>                                     <td><strong>Column 2</strong></td>
>                                 </tr>
>                                 <tr>
>                                     <td>Column 1</td>
>                                     <td>Column 2</td>
>                                 </tr>
>                                 <tr>
>                                     <td>Column 1</td>
>                                     <td>Column 2</td>
>                                 </tr>
>                             </table>
>                         </div>
>                     </formatted2>
>                 </instance>
>             </xforms:instance>
>
>             <!-- instance to hold the serialised xhtml -->
>             <xforms:instance id="styled-formatted">
>                 <xhtml:div/>
>             </xforms:instance>
>
>             <!-- binding to serialise instance xhtml node -->
>             <!-- change /formatted/ to /formatted1/, /formatted2/ in
the

>                 "calculate" attribute to show different behaviours -->
>             <xforms:bind nodeset="instance('styled-formatted')"
>
> calculate="saxon:serialize(instance('instance')/formatted/xhtml:div ,
> 'html')"/>
>             </xforms:model>
>         </xhtml:head>
>
>     <xhtml:body>
>         <xhtml:h1>Example XHTML instance</xhtml:h1>
>         <xhtml:fieldset>
>             <xhtml:legend>XHTML</xhtml:legend>
>                 <xforms:output ref="instance('styled-formatted')"
> appearance="xxforms:html"  />
>         </xhtml:fieldset>
>     </xhtml:body>
> </xhtml:html>
>
>
>
>
>
>
> -----Original Message-----
> From: Erik Bruchez [mailto:[hidden email]] On Behalf Of Erik
Bruchez

> Sent: 25 November 2005 14:23
> To: [hidden email]
> Subject: Re: [ops-users] Inserting HTML from an instance into a page
>
> Stephen Bayliss wrote:
>  > I managed to succeed in inserting XHTML, from an instance, into a
> page,
>  > by using the following technique:
>  >
>  >     * Pipeline service call through an xforms:submission and page
> flow
>  >       to populate a node in my instance document with the XHTML to
be

>  >       inserted (this through some oxf:xslt to actually produce the
> XHTML)
>  >     * Xforms:bind with a calculate attribute, which uses
> saxon:serialize
>  >       to produce the serialized HTML, to another instance
>  >     * Xforms:output control bound to this second instance document
>  >
>  > The purpose of this was to produce an XHTML-styled presentation of
> some
>  > XML data.
>  >
>  > However, the process seems very sensitive to namespaces: The only
>  > way I could get it working is to ensure that xhtml is defined as
the
>  > default namespace in the XSL that creates the XHTML (ie none of the
>  > tags actually specify the xhtml: namespace prefix).  Additionally,
>  > extra namespace definitions may get inserted through the XSL and
>  > pipeline processing; to prevent these appearing in my instance node
>  > I found it necessary to declare them at the start of the instance.
>  >
>  > Without doing this I got errors like this in the browser:
>  >
>  > org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes
must
>  > be created before the children of an element node when evaluating
>  >
>
'saxon:serialize(instance('instance')/formattedMetadataRecord/xhtml:div
>  > , 'html')'
>  >
>  > Presumably this is because the DOM is constructed by client-side
>  > javascript, and the javascript is doing simple text processing, and
>  > therefore having problems with namespace prefixes, or something
like

>  > this?
>
> OPS doesn't do any client-side DOM manipulations related to XForms
> instances (only some related to the HTML DOM for displaying controls),
> so that would not be the right explanation ;-)
>
>  > I can mock up an example of this if necessary.
>
> Sure. Try also to serialize to text directly from XPL, and return a
> serialized string with the response of the submission. That's what we
> do, the the help of the HTML formatter, to display in HTML the content
> of XForms instances in examples such as "XForms Controls" and "Wizard
> with Switch".
>
> -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
>
>
>


--
Blog (XML, Web apps, Open Source): http://www.orbeon.com/blog/




--
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: Inserting HTML from an instance into a page

Alessandro  Vernet
Administrator
Stephen,

Let us know if you find something about this!

Alex

On 12/6/05, Stephen Bayliss <[hidden email]> wrote:

> Alex
>
> Thanks for that -- I agree, it does seem to be a Saxon issue, best
> directed at their mailing lists.
>
> Steve
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of
> Alessandro Vernet
> Sent: 01 December 2005 23:04
> To: [hidden email]
> Subject: Re: [ops-users] Inserting HTML from an instance into a page
>
> Hi Stephen,
>
> I modified the example you sent to add an <xforms:output> without the
> HTML appearance, so we can see what is returned by the
> saxon:serialize() function. Looking at the cases you mention in your
> email:
>
> 1) Exactly what you typed is returned:
>
> <div xmlns:xhtml="http://www.w3.org/1999/xhtml"
> xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
> xmlns:xforms="http://www.w3.org/2002/xforms"
> xmlns="http://www.w3.org/1999/xhtml"> <table> <tr> <td> <strong>Column
> 1</strong> </td> <td> <strong>Column 2</strong> </td> </tr> <tr>
> <td>Column 1</td> <td>Column 2</td> </tr> <tr> <td>Column 1</td>
> <td>Column 2</td> </tr> </table> </div>
>
> This works, as there is no prefix on the HTML elements.
>
> 2) In the second case you get as well exactly what you typed:
>
> <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"
> xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
> xmlns:xforms="http://www.w3.org/2002/xforms"> <xhtml:table> <xhtml:tr>
> <xhtml:td> <xhtml:strong>Column 1 </xhtml:strong> </xhtml:td>
> <xhtml:td> <xhtml:strong>Column 2 </xhtml:strong> </xhtml:td>
> </xhtml:tr> <xhtml:tr> <xhtml:td>Column 1</xhtml:td> <xhtml:td>Column
> 2</xhtml:td> </xhtml:tr> <xhtml:tr> <xhtml:td>Column 1</xhtml:td>
> <xhtml:td>Column 2</xhtml:td> </xhtml:tr> </xhtml:table> </xhtml:div>
>
> That does not work, even on Firefox. I guess the browser doesn't like
> the prefixes there.
>
> 3) In the third case, Saxon throws an exception.
>
> Now for this to work, you obviously need return elements without
> prefixes. So only the first method works. Is there a way to tell the
> saxon:serialize() function to remove the prefixes (for the second
> case)? Why is saxon:serialize() throwing an exception in the third
> case? I don't have an answer to those questions, and if I were you, I
> would ask them in the Saxon mailing list.
>
> I have also attached your test case, just slightly modified so it
> works on the XForms sandbox.
>
> Alex
>
> On 11/28/05, Stephen Bayliss <[hidden email]> wrote:
> > Hi Erik
> >
> > It was the "XForms Controls" and "Wizard with Switch" examples that I
> > followed.
> >
> > Here's a mocked up example.  Just a single "view" file, called from
> the
> > following page flow:
> >     <page id="example-html" path-info="/example-html"
> > view="/example-html/view.xhtml"/>
> >
> > I've pasted the whole view.xhtml below.
> >
> > There are three different example instance nodes used to show the
> > different behaviours that seem anomalous.
> >
> > You can see the different behaviours by changing the calculate
> attribute
> > of the <xforms:bind> to reference the different instance nodes.
> >
> > 1. xhtml as default namespace
> > calculate="saxon:serialize(instance('instance')/formatted/xhtml:div ,
> > 'html')"
> >
> > This example renders fine
> >
> > 2. xhtml: used as namespace prefix for the xhtml tags
> > calculate="saxon:serialize(instance('instance')/formatted1/xhtml:div ,
> > 'html')"
> >
> > This does not render correctly even though it's valid xhtml; it's as
> if
> > the xhtml tags have not been recognised, so just literal text has been
> > output.
> >
> > 3. xhtml as default namespace; additional namespace declared as well
> > calculate="saxon:serialize(instance('instance')/formatted2/xhtml:div ,
> > 'html')"
> >
> > This produces an error even though it's valid xml:
> > org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes must
> be
> > created before the children of an element node when evaluating
> > 'saxon:serialize(instance('instance')/formatted2/xhtml:div , 'html')'
> >
> > Steve
> >
> > ------------------------
> > /example-html/view.xhtml
> > ------------------------
> > <xhtml:html
> >     xmlns:xhtml="http://www.w3.org/1999/xhtml"
> >     xmlns:xforms="http://www.w3.org/2002/xforms"
> >     xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">
> >     <xhtml:head>
> >         <xhtml:title>Example - XHTML instance</xhtml:title>
> >         <xforms:model>
> >             <xforms:instance id="instance">
> >                 <instance>
> >                     <!-- xhtml as default namespace: correctly
> rendered
> > -->
> >                     <formatted>
> >                         <div xmlns="http://www.w3.org/1999/xhtml">
> >                             <table>
> >                                 <tr>
> >                                     <td><strong>Column 1</strong></td>
> >                                     <td><strong>Column 2</strong></td>
> >                                 </tr>
> >                                 <tr>
> >                                     <td>Column 1</td>
> >                                     <td>Column 2</td>
> >                                 </tr>
> >                                 <tr>
> >                                     <td>Column 1</td>
> >                                     <td>Column 2</td>
> >                                 </tr>
> >                             </table>
> >                         </div>
> >                     </formatted>
> >                     <!-- xhtml tags use xhtml namespace prefix:
> > incorrectly rendered -->
> >                     <formatted1>
> >                         <xhtml:div>
> >                             <xhtml:table>
> >                                 <xhtml:tr>
> >                                     <xhtml:td><xhtml:strong>Column
> > 1</xhtml:strong></xhtml:td>
> >                                     <xhtml:td><xhtml:strong>Column
> > 2</xhtml:strong></xhtml:td>
> >                                 </xhtml:tr>
> >                                 <xhtml:tr>
> >                                     <xhtml:td>Column 1</xhtml:td>
> >                                     <xhtml:td>Column 2</xhtml:td>
> >                                 </xhtml:tr>
> >                                 <xhtml:tr>
> >                                     <xhtml:td>Column 1</xhtml:td>
> >                                     <xhtml:td>Column 2</xhtml:td>
> >                                 </xhtml:tr>
> >                             </xhtml:table>
> >                         </xhtml:div>
> >                     </formatted1>
> >                     <!-- xhtml as default namespace; additional
> > namespace declared, causes error -->
> >                     <formatted2>
> >                         <div xmlns="http://www.w3.org/1999/xhtml"
> > xmlns:example="http://nothing.here">
> >                             <table>
> >                                 <tr>
> >                                     <td><strong>Column 1</strong></td>
> >                                     <td><strong>Column 2</strong></td>
> >                                 </tr>
> >                                 <tr>
> >                                     <td>Column 1</td>
> >                                     <td>Column 2</td>
> >                                 </tr>
> >                                 <tr>
> >                                     <td>Column 1</td>
> >                                     <td>Column 2</td>
> >                                 </tr>
> >                             </table>
> >                         </div>
> >                     </formatted2>
> >                 </instance>
> >             </xforms:instance>
> >
> >             <!-- instance to hold the serialised xhtml -->
> >             <xforms:instance id="styled-formatted">
> >                 <xhtml:div/>
> >             </xforms:instance>
> >
> >             <!-- binding to serialise instance xhtml node -->
> >             <!-- change /formatted/ to /formatted1/, /formatted2/ in
> the
> >                 "calculate" attribute to show different behaviours -->
> >             <xforms:bind nodeset="instance('styled-formatted')"
> >
> > calculate="saxon:serialize(instance('instance')/formatted/xhtml:div ,
> > 'html')"/>
> >             </xforms:model>
> >         </xhtml:head>
> >
> >     <xhtml:body>
> >         <xhtml:h1>Example XHTML instance</xhtml:h1>
> >         <xhtml:fieldset>
> >             <xhtml:legend>XHTML</xhtml:legend>
> >                 <xforms:output ref="instance('styled-formatted')"
> > appearance="xxforms:html"  />
> >         </xhtml:fieldset>
> >     </xhtml:body>
> > </xhtml:html>
> >
> >
> >
> >
> >
> >
> > -----Original Message-----
> > From: Erik Bruchez [mailto:[hidden email]] On Behalf Of Erik
> Bruchez
> > Sent: 25 November 2005 14:23
> > To: [hidden email]
> > Subject: Re: [ops-users] Inserting HTML from an instance into a page
> >
> > Stephen Bayliss wrote:
> >  > I managed to succeed in inserting XHTML, from an instance, into a
> > page,
> >  > by using the following technique:
> >  >
> >  >     * Pipeline service call through an xforms:submission and page
> > flow
> >  >       to populate a node in my instance document with the XHTML to
> be
> >  >       inserted (this through some oxf:xslt to actually produce the
> > XHTML)
> >  >     * Xforms:bind with a calculate attribute, which uses
> > saxon:serialize
> >  >       to produce the serialized HTML, to another instance
> >  >     * Xforms:output control bound to this second instance document
> >  >
> >  > The purpose of this was to produce an XHTML-styled presentation of
> > some
> >  > XML data.
> >  >
> >  > However, the process seems very sensitive to namespaces: The only
> >  > way I could get it working is to ensure that xhtml is defined as
> the
> >  > default namespace in the XSL that creates the XHTML (ie none of the
> >  > tags actually specify the xhtml: namespace prefix).  Additionally,
> >  > extra namespace definitions may get inserted through the XSL and
> >  > pipeline processing; to prevent these appearing in my instance node
> >  > I found it necessary to declare them at the start of the instance.
> >  >
> >  > Without doing this I got errors like this in the browser:
> >  >
> >  > org.orbeon.saxon.event.NoOpenStartTagException: Namespace nodes
> must
> >  > be created before the children of an element node when evaluating
> >  >
> >
> 'saxon:serialize(instance('instance')/formattedMetadataRecord/xhtml:div
> >  > , 'html')'
> >  >
> >  > Presumably this is because the DOM is constructed by client-side
> >  > javascript, and the javascript is doing simple text processing, and
> >  > therefore having problems with namespace prefixes, or something
> like
> >  > this?
> >
> > OPS doesn't do any client-side DOM manipulations related to XForms
> > instances (only some related to the HTML DOM for displaying controls),
> > so that would not be the right explanation ;-)
> >
> >  > I can mock up an example of this if necessary.
> >
> > Sure. Try also to serialize to text directly from XPL, and return a
> > serialized string with the response of the submission. That's what we
> > do, the the help of the HTML formatter, to display in HTML the content
> > of XForms instances in examples such as "XForms Controls" and "Wizard
> > with Switch".
> >
> > -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
> >
> >
> >
>
>
> --
> Blog (XML, Web apps, Open Source): http://www.orbeon.com/blog/
>
>
>
>
>
> --
> 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
>
>
>

--
Blog (XML, Web apps, Open Source): http://www.orbeon.com/blog/



--
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
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet