xforms and recursion

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

xforms and recursion

Mark Waschkowski
Hi,

If I have a data structure that is arbitrarily deep, is there any way
to write a repeat element that will recurse within itself to traverse
the entire data structure?

Thanks,

Mark

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

Aaron Reed
Hi Mark,

I can't say that I've ever needed to do it before, so I'm not sure.  You
could try asking on the W3C mailing list, too.  Someone there might have
tried it before.

--Aaron

mwaschkowski wrote:

> Hi,
>
> If I have a data structure that is arbitrarily deep, is there any way
> to write a repeat element that will recurse within itself to traverse
> the entire data structure?
>
> Thanks,
>
> Mark
>
_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

Dan McCreary
This both an interesting and fairly common problem.  Think of a UML
diagram with subclasses, the friends-of-a-friend (FOAF) rdf standards
or trying to edit FreeMind (the wonderful open-source mindmap editor)
where nodes contain nodes.  FreeMind stores its data in compressed XML
documents so I can see how users would want to build a quick GUI for
editing the nodes.

Can you decompose the XML Schema into a list of nodes and arcs?  If
you can do this I have a few ideas...

We have a metadata registry that we use XForms editor on, but we only
edit one "node" at a time.  The nodes are all stored in XML database.
The XForm application just allows you to navigate to the next node
(subclass/superclass relationships).  If you can pass an XPath
expression to a node editor and then have it update just that node.

You could also create a little servlet with Jetty or some other
lightweight framework that does a little bit of xslt on the main XML
file if it is large. The service would take and XPath expression in
and return the node for editing.

One approach would be to combine some XForms and an XSL that passes
depth as a parameter.

I will have to think about this further.  Let me know if you come up
with any solutions.  I will be glad to post an example in the XForms
Tutorial and Cookbook.

- Dan

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

Dan McCreary
One solution is to restrict the nodeset attribute in the repeat using
and instance value.

So if you had node and links structure like:

<node>
      <node-id>usa</node-id>
      <links>
         <link-id>states-in-the-us</link-id>
         <node>
            <node-id>california</node-id>
         </node>
         <node>
            <node-id>minnesota</node-id>
            <links>
               <link-id>cities-in-minnesota</link-id>
               <node>
                  <node-id>minneapolis</node-id>
               </node>

You could use something like this:

<xf:repeat nodeset="//node[node-id=instance('path')/current-node-id]/
link/node" id="repeat-node1">

Where instance('path')/current-node-id]/link/node finds all sub-nodes
of the current node.

I tested this a bit and I put little graph editor demo in the XForms
Tutorial and Cookbook when I get a chance.

- Dan

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

FraserHore-2
I've been trying the following approach.  I set a repeat nodeset to be
the first item at each level of the hierarchy.  Then I repeat through
each of the first item's siblings in a nested repeat.  Unfortunately,
the sibling is in the context of the nodeset not the whole instance so
the first following sibling is not the following sibling in the
instance but the following sibling in the nodeset.  Perhaps this
approach spark ideas in someone else who might get it to work.

instance file RecursionInstance.xml:

<?xml version="1.0" encoding="UTF-8"?>
<data xmlns:xforms="http://www.w3.org/2002/xforms">
                <items>
      <item>
                                <firstname>Joe</firstname>
                                <lastname>Blogs</lastname>
                                <hobbies>
                                        <hobbie>tennis</hobbie>
                                </hobbies>
                        </item>
      <item>
                                <firstname>John</firstname>
                                <lastname>Doe</lastname>
                                <hobbies>
                                        <hobbie>Hockey</hobbie>
                                </hobbies>
                        </item>
      <item>
                                <firstname>Allen</firstname>
                                <lastname>Stubing</lastname>
                                <hobbies>
                                        <hobbie>Soccer</hobbie>
                                </hobbies>
                        </item>
                </items>
        </data>

xForm file RecursionTest.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xforms="http://www.w3.org/2002/xforms">
   <head>
    <title>Recursion Test</title>
    <xforms:model>
     <xforms:instance id="RecursionInstance"
src="RecursionInstance.xml" xmlns=""/>
     <xforms:submission id="save" method="put"
action="RecursionInstance.xml" instance="RecursionInstance"/>
    </xforms:model>
     <link href="default.css" rel="stylesheet"/>
   </head>
   <body>

<!-- descendant-or-self::*/child::*[1] to get the first item at each
level of the hierarchy -->
        <xforms:repeat nodeset="/data/items/descendant-or-self::*/
child::*[1]">
           <xforms:group>
    <xforms:input ref="*">
      <xforms:label>First Item: </xforms:label>
    </xforms:input>

<!-- following-sibling::* to get the siblings of the first item -->
                <xforms:repeat nodeset="following-sibling::*">
    <xforms:input ref="*">
      <xforms:label>Siblings: </xforms:label>
    </xforms:input>
                </xforms:repeat>
           </xforms:group>
        </xforms:repeat>

        <xforms:submit submission="save">
            <xforms:label>Save</xforms:label>
        </xforms:submit>

   </body>
</html>

Styling in default.css to help see what's going on and indent levels
of the hierarchy

xf|group {
        display:block;
        width:100%;
        background-color: rgb(204, 204, 153);
        margin-top: 5px;
        margin-bottom: 5px;
        margin-right: 7px;
        border: medium groove black;
}

xf|group xf|group, xf|group xf|repeat {
        margin-left: 21px;
        width: 95%;
        background-color: rgb(216, 216, 177);
}


_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

Dan McCreary
In reply to this post by Aaron Reed
Here is an example that is almost working:

http://en.wikibooks.org/wiki/XForms/Graph_Viewer

I can not seem to get the setvalue to work inside the repeat.

- Dan

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

FraserHore-2
I haven't had a chance to try out your example but i thought perhaps
using index to set the value of current-node-id would solve your
problem.  Something like:

<xf:setvalue ref="instance('path')/current-node-id" value="//node[node-
id=instance('path')/current-node-id]/links/
node[position()=index('repeat-node1')]/node-id" />

I hope it works!!

Cheers,

Fraser

On Apr 23, 6:20 pm, Dan <[hidden email]> wrote:
> Here is an example that is almost working:
>
> http://en.wikibooks.org/wiki/XForms/Graph_Viewer
>
> I can not seem to get the setvalue to work inside the repeat.
>
> - Dan


_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

FraserHore-2
In reply to this post by Dan McCreary
I haven't had a chance to try this yet but i think the following might
work:

<xf:setvalue ref="instance('path')/current-node-id"
value="instance('saved-data')//node[node-id=instance('path')/current-
node-id]/links/node[position()=index('repeat-node1')/node-id" />

I hope it works!!

Cheers,

Fraser

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

Dan McCreary
Great idea!  That worked with a small fix of adding in the "]" after
the index('repeat-node1').

Thanks!

Here is the final version:

<xf:setvalue ref="instance('path')/current-node-id"
value="instance('saved-data')//node[node-id=instance('path')/current-
node-id]/links/node[position()=index('repeat-node1')]/node-id" />


On Apr 23, 12:09 pm, [hidden email] wrote:

> I haven't had a chance to try this yet but i think the following might
> work:
>
> <xf:setvalue ref="instance('path')/current-node-id"
> value="instance('saved-data')//node[node-id=instance('path')/current-
> node-id]/links/node[position()=index('repeat-node1')/node-id" />
>
> I hope it works!!
>
> Cheers,
>
> Fraser


_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

FraserHore-2
There remains a major need for some way to iterate through and display
nicely an xml hierarchy.  I've been trying a variety of approaches
with repeats but no luck yet.  The following are some ideas for
parameters that a repeat control could have to give lots of
flexibility:

depth="{number}" maximum depth level to be repeated
sortBy="{node name or result of xpath expression}"  element or
attribute to use for sorting
sort="{ascending|descending|randomize}" sort type
number="{number} number of nodes to repeat - in xforms 1.1 spec
appearance="{flat|tree|grid}" choices for the layout and functionality
of the result

It would still be nice to have some type of iterating control such as
foreach within which you could put "if, then, else" type conditional
tests and xforms actions.

Just dreaming for the time being i guess.  But if someone has a short
term workaround for displaying a hierarchical list of items based on
the hierarchy in the xml instance i'm very keen to learn about it.

Cheers,

Fraser

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

Dan McCreary
On Apr 24, 4:42 am, [hidden email] wrote:
> There remains a major need for some way to iterate through and display
> nicely an xml hierarchy.  I've been trying a variety of approaches
> with repeats but no luck yet.

Yes, I agree with you totally here.  When we teach XForms to students
we try to always tell them if they keep a clear picture of the
instance tree in their mind, then most XPath expressions can be
quickly understood.  The setvalue statements inside of repeats are
clearly not intuitive and a obstacle for adoption of the current
version of XForms.  The current() function in XForms 1.1 will help a
little but I like your ideas.

> The following are some ideas for parameters that a repeat control could have to give lots of
> flexibility:

I hope that someone from the w3c is listening...;-)

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

Aaron Reed
Someone from the W3C might be listening, but it would be a much better
idea to post requests and concerns about the specs directly to their
public mailing list (http://lists.w3.org/Archives/Public/www-forms/).
The more eyes that see them, the higher likelihood for them to be addressed.

--Aaron

Dan wrote:

> On Apr 24, 4:42 am, [hidden email] wrote:
>> There remains a major need for some way to iterate through and display
>> nicely an xml hierarchy.  I've been trying a variety of approaches
>> with repeats but no luck yet.
>
> Yes, I agree with you totally here.  When we teach XForms to students
> we try to always tell them if they keep a clear picture of the
> instance tree in their mind, then most XPath expressions can be
> quickly understood.  The setvalue statements inside of repeats are
> clearly not intuitive and a obstacle for adoption of the current
> version of XForms.  The current() function in XForms 1.1 will help a
> little but I like your ideas.
>
>> The following are some ideas for parameters that a repeat control could have to give lots of
>> flexibility:
>
> I hope that someone from the w3c is listening...;-)
>
_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xforms and recursion

David-348
In reply to this post by FraserHore-2
On Apr 24, 4:42 am, [hidden email] wrote:

> There remains a major need for some way to iterate through and display
> nicely an xml hierarchy.  I've been trying a variety of approaches
> with repeats but no luck yet.  The following are some ideas for
> parameters that a repeat control could have to give lots of
> flexibility:
>
> depth="{number}" maximum depth level to be repeated
> sortBy="{node name or result of xpath expression}"  element or
> attribute to use for sorting
> sort="{ascending|descending|randomize}" sort type
> number="{number} number of nodes to repeat - in xforms 1.1 spec
> appearance="{flat|tree|grid}" choices for the layout and functionality
> of the result
>
> It would still be nice to have some type of iterating control such as
> foreach within which you could put "if, then, else" type conditional
> tests and xforms actions.
>
> Just dreaming for the time being i guess.  But if someone has a short
> term workaround for displaying a hierarchical list of items based on
> the hierarchy in the xml instance i'm very keen to learn about it.
>
> Cheers,
>
> Fraser

test

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms