. . . so how does 'conditional rendering' of an xform, based on instance data, work?

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

. . . so how does 'conditional rendering' of an xform, based on instance data, work?

Michiel Roos [netcreators]
Dear list,

I would like to render a certain image (or different background color on
a td) based on the content of an instance.

Is there a clear example of how to do this lying around somewhere?

<root>
        <animal>
                <name>dog</name>
                <sound>bark</sound>
        </animal>
        <animal>
                <name>cat</name>
                <sound>meaow</sound>
        </animal>
</root>

I tried this to no avail:
<xsl:stylesheet version="2.0"
        xmlns="http://www.w3.org/1999/XSL/Transform"
        xmlns:xforms="http://www.w3.org/2002/xforms"
        xmlns:xhtml="http://www.w3.org/1999/xhtml"
        xmlns:xi="http://www.w3.org/2001/XInclude"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
        <xsl:template match="/">
                <xhtml:html>
                        <xhtml:head>
                                <xhtml:title>Test</xhtml:title>
                                <xforms:model id="main-model">
                                        <xforms:instance id="instance">
                                                <xi:include href="input:instance"/>
                                        </xforms:instance>
                                </xforms:model>
                        </xhtml:head>
                        <xhtml:body>
                                <xforms:group ref="/root">
                                                <xforms:repeat nodeset="animal[position()]" >
                                                        <xforms:output ref="name" />
                                                        <xsl:choose>
                                                                <xsl:when test="sound = 'bark'">
                                                                        <xhtml:span style="background-color: red">; barks</xhtml:span>
                                                                </xsl:when>
                                                                <xsl:otherwise>
                                                                        <xhtml:span>; not a barking animal</xhtml:span>
                                                                </xsl:otherwise>
                                                        </xsl:choose>
                                                        <xhtml:br />
                                                </xforms:repeat>
                                </xforms:group>
                        </xhtml:body>
                </xhtml:html>
        </xsl:template>
</xsl:stylesheet>



--

Cheers,


Michiel Roos
netcreators.com



--
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: . . . so how does 'conditional rendering' of an xform, based on instance data, work?

Daniel E. Renfer
Michiel,

Your problem is coming from the fact that any xsl instructions are
parsed when the page is being generated. You want a test that'll run
after the page has been loaded. There are several ways to do this, but
something like the following should do the trick. (untested)

<xforms:group ref=".[sound = 'bark']">
    <xhtml:span style="background-color: red">; barks</xhtml:span>
</xforms:group>
<xforms:group ref=".[not(sound = 'bark')]">
    <xhtml:span>; not a barking animal</xhtml:span>
</xforms:group>

if you're doing more than this little example, then you might want to
look into the switch module [1]

[1]: http://www.w3.org/TR/xforms11/#ui-switch-module

--
Daniel E. Renfer
http://kronkltd.net/

On 1/4/07, Michiel Roos <[hidden email]> wrote:

> Dear list,
>
> I would like to render a certain image (or different background color on
> a td) based on the content of an instance.
>
> Is there a clear example of how to do this lying around somewhere?
>
> <root>
>         <animal>
>                 <name>dog</name>
>                 <sound>bark</sound>
>         </animal>
>         <animal>
>                 <name>cat</name>
>                 <sound>meaow</sound>
>         </animal>
> </root>
>
> I tried this to no avail:
> <xsl:stylesheet version="2.0"
>         xmlns="http://www.w3.org/1999/XSL/Transform"
>         xmlns:xforms="http://www.w3.org/2002/xforms"
>         xmlns:xhtml="http://www.w3.org/1999/xhtml"
>         xmlns:xi="http://www.w3.org/2001/XInclude"
>         xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
>         <xsl:template match="/">
>                 <xhtml:html>
>                         <xhtml:head>
>                                 <xhtml:title>Test</xhtml:title>
>                                 <xforms:model id="main-model">
>                                         <xforms:instance id="instance">
>                                                 <xi:include href="input:instance"/>
>                                         </xforms:instance>
>                                 </xforms:model>
>                         </xhtml:head>
>                         <xhtml:body>
>                                 <xforms:group ref="/root">
>                                                 <xforms:repeat nodeset="animal[position()]" >
>                                                         <xforms:output ref="name" />
>                                                         <xsl:choose>
>                                                                 <xsl:when test="sound = 'bark'">
>                                                                         <xhtml:span style="background-color: red">; barks</xhtml:span>
>                                                                 </xsl:when>
>                                                                 <xsl:otherwise>
>                                                                         <xhtml:span>; not a barking animal</xhtml:span>
>                                                                 </xsl:otherwise>
>                                                         </xsl:choose>
>                                                         <xhtml:br />
>                                                 </xforms:repeat>
>                                 </xforms:group>
>                         </xhtml:body>
>                 </xhtml:html>
>         </xsl:template>
> </xsl:stylesheet>
>
>
>
> --
>
> Cheers,
>
>
> Michiel Roos
> netcreators.com


--
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: . . . so how does 'conditional rendering' of an xform, based on instance data, work?

Michiel Roos [netcreators]
Daniel E. Renfer wrote:

> Michiel,
>
> Your problem is coming from the fact that any xsl instructions are
> parsed when the page is being generated. You want a test that'll run
> after the page has been loaded. There are several ways to do this, but
> something like the following should do the trick. (untested)
>
> <xforms:group ref=".[sound = 'bark']">
>    <xhtml:span style="background-color: red">; barks</xhtml:span>
> </xforms:group>
> <xforms:group ref=".[not(sound = 'bark')]">
>    <xhtml:span>; not a barking animal</xhtml:span>
> </xforms:group>
Cheers Daniel,

That worked.

> if you're doing more than this little example, then you might want to
> look into the switch module [1]
>
> [1]: http://www.w3.org/TR/xforms11/#ui-switch-module


--

Met vriendelijke groet,


Michiel Roos
netcreators.com



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