Hello All,

I have been trying to resolve an issue that I thought I had fixed by
using the latest build, but no luck.

I am building a XML Schema designer and Xforms generator using
XSLTforms. I want to add both elements and types to a schema list with
the list appearing in a repeat. Sometimes adding just an element and
sometimes both an element and a type, with all the elements appearing
first, then followed by the all the types (it would be good if they
could display in alphabetical order within these categories).

On adding an element, I want to use xf:setindex to select the element
just added (the last element in the list).

The unusual behaviour is that setindex works when I add both an
element and a type but doesn't when I add just the element. The
different behaviour can be seen by commenting out the line in the code
below that inserts the type (as marked below in capitals).

Maybe I am doing something wrong but I seen no errors.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="build/xsltforms.xsl" type="text/xsl"?>
<?xsltforms-options debug="yes"?>
<html xmlns="http://www.w3.org/1999/xhtml";
xmlns:xf="http://www.w3.org/2002/xforms";
        xmlns:ev="http://www.w3.org/2001/xml-events";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
        xmlns:s2x="http://www.sourceforge.net/schema2xforms";
xmlns:sch="http://purl.oclc.org/dsdl/schematron";>
        <head>
                <title />
                <xf:model id="model1">
                        <xf:instance id="xml_schema_elements">
                                <s2x:data>
                                        <xs:element name=""/>
                                        <xs:type name=""/>
                                </s2x:data>
                        </xf:instance>
                        <xf:instance id="built_schema">
                                <xs:schema>
                                        <s2x:data />
                                </xs:schema>
                        </xf:instance>
                        <xf:instance id="temp">
                                <xs:data>
                                        <s2x:posn />
                                </xs:data>
                        </xf:instance>
                </xf:model>
                <style type="text/css">
                .xforms-repeat-item-selected { background-color:lightblue; }
                </style>
        </head>
        <body>
                <div>
                        <xf:group 
ref="instance('xml_schema_elements')/xs:element">
                                <xf:input id="new_element_name" ref="@name" />
                                <xf:trigger>
                                        <xf:label>Add</xf:label>
                                        <xf:hint>Adds a new schema 
element</xf:hint>
                                        <xf:action ev:event="DOMActivate"
                                                if="string-length(@name) &gt; 0 
and
not(instance('built_schema')/*/@name = current()/@name)">
                                                <xf:setvalue 
ref="instance('temp')/s2x:posn"
value="count(instance('built_schema')/xs:element)+1"/>
                                                <xf:setvalue 
ref="instance('xml_schema_elements')/xs:type/@name"
value="current()/@name"/>
                                                <xf:insert 
nodeset="instance('built_schema')/*"
origin="current()" at="instance('temp')/s2x:posn" position="before" />
                                                <!-- COMMENT OUT THE
FOLLOWING LINE -->
                                                <xf:insert 
nodeset="instance('built_schema')/*"
origin="instance('xml_schema_elements')/xs:type"/>
                                                <xf:setvalue 
ref="current()/@name" value="" />
                                                <xf:setvalue 
ref="instance('xml_schema_elements')/xs:type/@name"
value=""/>
                                                <xf:setfocus 
control="new_element_name" />
                                                <xf:setindex 
repeat="elements_and_types"
index="instance('temp')/s2x:posn"/>
                                        </xf:action>
                                        <xf:action ev:event="DOMActivate"
                                                if="string-length(@name) &gt; 0 
and
instance('built_schema')/*/@name = current()/@name">
                                                <xf:message>
                                                        An element with name
                                                        <span 
style="font-weight:bold;">
                                                                <xf:output 
ref="@name" />
                                                        </span>
                                                        already exists
                                                </xf:message>
                                                <xf:setfocus 
control="new_element_name" />
                                        </xf:action>
                                </xf:trigger>
                                <xf:trigger>
                                        <xf:label>Set Index</xf:label>
                                        <xf:hint>Adds a new schema 
element</xf:hint>
                                        <xf:action ev:event="DOMActivate">
                                                <xf:setindex 
repeat="elements_and_types"
index="instance('temp')/s2x:posn"/>
                                        </xf:action>
                                </xf:trigger>
                        </xf:group>
                </div>
                <div>
                        <xf:repeat 
nodeset="instance('built_schema')/*[not(self::s2x:data)]"
                                id="elements_and_types">
                                <div>
                                        <xf:output 
value="if(name(.)='xs:element','e:','t:')"
/><xf:output value="@name" />
                                </div>
                        </xf:repeat>
                </div>
        </body>
</html>

Thanks for your assistance and all the best for 2012!

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Xsltforms-support mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xsltforms-support

Reply via email to