current() function inside an itemset

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

current() function inside an itemset

chrisswick
Hi,

I am trying to repeat through a nodeset, and have a select1's itemset
use the current() function to filter its data based on its repeat
position. I was however able to use a repeat within a repeat which
uses the current() function to filter its data based on its parent
repeat position. Below is a description and an example. I'm thinking
the itemset's noseset attribute should work the same as the repeat's
nodeset attribute?

DESCRIPTION:
Instance 1 - contains Store Types
Instance 2 - contains Products Types which are assigned to any number
of Store Types
Instance 3 - contains my selected Store Type in the repeat, and
Selected Product Type that is assigned to the coinciding selected
Store Type
The example below shows that a repeat can filter using the current()
function, but the itemset cannot.


EXAMPLE:
<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">


  <head>
    <title>Test</title>
    <xf:model>

      <xf:instance id="my-list" xmlns="">
        <data>
          <item>
            <storeID />
            <productID />
          </item>
        </data>
      </xf:instance>

      <xf:instance id="stores-types" xmlns="">
        <data>
          <store id="1">
            <name>Department Store</name>
          </store>
          <store id="2">
            <name>Grocery Store</name>
          </store>
          <store id="3">
            <name>Specialty Store</name>
          </store>
        </data>
      </xf:instance>

      <xf:instance id="product-types" xmlns="">
        <data>
          <product id="1">
            <name>Appliances</name>
            <stores>
              <store>
                <id>1</id>
              </store>
            </stores>
          </product>
          <product id="2">
            <name>Food</name>
            <stores>
              <store>
                <id>3</id>
              </store>
              <store>
                <id>2</id>
              </store>
            </stores>
          </product>
          <product id="3">
            <name>Clothing</name>
            <stores>
              <store>
                <id>1</id>
              </store>
              <store>
                <id>3</id>
              </store>
            </stores>
          </product>
        </data>
      </xf:instance>

    </xf:model>
  </head>

  <body>

    <xf:repeat nodeset="instance('my-list')/item">

      <xf:select1 ref="storeID" selection="closed">
        <xf:label>Select a Store Type</xf:label>
        <xf:itemset nodeset="instance('stores-types')/store">
          <xf:label ref="name" />
          <xf:value ref="@id" />
        </xf:itemset>
      </xf:select1>

      <xf:repeat nodeset="instance('product-types')/product[stores/
store/id = current()/storeID]">
        <xf:output ref="name" />
      </xf:repeat>
      <br />
      <br />
    </xf:repeat>

    <xf:trigger>
      <xf:label>Add</xf:label>
      <xf:action ev:event="DOMActivate">
        <xf:insert nodeset="instance('my-list')/item" at="last()"
position="after" />
        <xf:setvalue ref="instance('my-list')/item[last()]/storeID"
value="" />
        <xf:setvalue ref="instance('my-list')/item[last()]/productID"
value="" />
      </xf:action>
    </xf:trigger>


    <br />
    <br />
    <br />

    <xf:repeat nodeset="instance('my-list')/item">

      <xf:select1 ref="storeID" selection="closed">
        <xf:label>Select a Store Type</xf:label>
        <xf:itemset nodeset="instance('stores-types')/store">
          <xf:label ref="name" />
          <xf:value ref="@id" />
        </xf:itemset>
      </xf:select1>

      <xf:select1 ref="productID" selection="closed">
        <xf:itemset nodeset="instance('product-types')/product[stores/
store/id = current()/storeID]">
          <xf:label ref="name" />
          <xf:value ref="@id" />
        </xf:itemset>
      </xf:select1>
      <br />
      <br />
    </xf:repeat>

    <xf:trigger>
      <xf:label>Add</xf:label>
      <xf:action ev:event="DOMActivate">
        <xf:insert nodeset="instance('my-list')/item" at="last()"
position="after" />
        <xf:setvalue ref="instance('my-list')/item[last()]/storeID"
value="" />
        <xf:setvalue ref="instance('my-list')/item[last()]/productID"
value="" />
      </xf:action>
    </xf:trigger>

  </body>

</html>

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

RE: current() function inside an itemset

Clark, John
> I am trying to repeat through a nodeset, and have a select1's itemset
> use the current() function to filter its data based on its repeat
> position.

>       <xf:select1 ref="productID" selection="closed">
>         <xf:itemset nodeset="instance('product-types')/product[stores/
> store/id = current()/storeID]">
>           <xf:label ref="name" />
>           <xf:value ref="@id" />
>         </xf:itemset>
>       </xf:select1>

The problem is that in the `xf:itemset` element, the context is no
longer at the `item` element over which the `xf:repeat` repeats, but at
the `productID` element, since the `ref` attribute changes the XPath
context.  As a result, the `storeID` you are trying to access is not a
child of the current node, but a sibling of that node.  The following
snippet (a replacement for the quoted snippet above) fixes this problem:

  <xf:select1 ref="productID" selection="closed">
    <xf:itemset nodeset="instance('product-types')/product[stores/
store/id = current()/../storeID]">
      <xf:label ref="name" />
      <xf:value ref="@id" />
    </xf:itemset>
  </xf:select1>

Take care,

    John L. Clark

===================================

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2007).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.



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