简体   繁体   中英

XForms repeat - JavaScript error

I am using XForms to build a web application with XML-DB eXist-db as backend. eXist transforms the XForms code into HTML and JavaScript.

First of all I got two instances:

<xf:instance xmlns="" id="results">
  <result>
    <ServiceDefinition>
      <InventoryLabel LastChange="2012-01-24">SVC380712435</InventoryLabel>
      <SystemName IPaddress="111.222.333.123">XXX</SystemName>
      <Service ServiceCategory="Internetservice">Web-Server</Service>
      <OSClass OperatingSystem="CentOS">UNIX</OSClass>
      <SystemType Manufacturer="VMware">VM</SystemType>
      <Backup/>
      <Location SystemContact="Max Power" AdminGroup="power">N22</Location>
    </ServiceDefinition>
    ....
  </result>
</xf:instance>

<xf:instance xmlns="" id="domain">
  <system name="XXX">
    <NIC MAC="00-50-56-ae-00-3c" 
         time="1329167846" missed="1323350247" state="inactive" 
         IP="111.222.333.123" LAN="Test"/>
  </system>
  ...
</xf:instance>

I want to build a table using xf:repeat to iterate through all the <ServiceDefinition> Elements in the 'results' instance. Every row contains a 'Status' column where I want to put the related 'state' information from the 'domain' instance.

This is the XForms code for the table:

    <div class="table">
    <table border="0">
       <thead>
          <tr>
             <th class="sysName">Hostname</th>
                  <th class="services">Service</th>
                  <th class="os">OS Class</th>
                  <th class="location">Location</th>
                  <th class="link">Details</th>
                  <th>Status</th>
                </tr>
              </thead>
              <tbody>
              <xf:repeat nodeset="instance('results')/result/ServiceDefinition" id="link-repeat">
                <tr>
                  <td class="sysName"><xf:output ref="SystemName"  /></td>
                  <td>
                    <xf:repeat nodeset="Service" class="row">
                      <div>
                        <xf:output ref="."/>
                      </div>
                    </xf:repeat>
                  </td>
                  <td class="os"><xf:output ref="OSClass"/> </td>
                  <td class="location"><xf:output ref="Location" /></td>
                  <td class="link">
                    <xf:trigger submission="view-entry" appearance="minimal" class="url">
                      <xf:label>View</xf:label>
                      <xf:action ev:event="DOMActivate">
                        <xf:setvalue ref="instance('URL-container')" 
                                   value="concat('serviceDetails.xql?svc=', instance('results')/result/ServiceDefinition[index('link-repeat')]/InventoryLabel)"/>
                        <xf:load ref="instance('URL-container')" />
                      </xf:action>
                    </xf:trigger>
                  </td>
                  <td>
                  <xf:output ref="instance('domain')/system[@name = instance('results')/result/ServiceDefinition[index('link-repeat')]/SystemName]/NIC/@state" />
                  </td>
                </tr>
                </xf:repeat>
                </tbody>
    </table>
    </div>

The problem seems to be this part:

<td>
  <xf:output ref="instance('domain')/system[@name = instance('results')/result/ServiceDefinition[index('link-repeat')]/SystemName]/NIC/@state" />
</td>

Is there something wrong with this expression? I want to get the state attribute of the system that matches the current node in the repeat statement. However when I load the page and the 'results'-instance consist of many items I get a Javascript error:

A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.
Script: http://test:8080/exist/xforms/xsltforms/xsltforms.js:771*

The line (in this case 771) always differs.

When the result instance is very small (up to about 20 Elements) it works as expected.

Any help or suggestion appreciated, I am new to all this, so please be patient.

Because XSLTForms has its own XPath engine written in JavaScript, browsers might be slow to evaluate expressions requiring to navigate through a lot of nodes, especially old versions of Internet Explorer.

Performance has been improved recently and you should try with latest build in SVN repository of XSLTForms at sourceforge.net.

Using the id() function is a possibility to heavily reduce evaluation time.

There is also an XSLTForms specific extension to indicate whether an instance contains only readonly data.

Did you try the Profiler (press F1 first) to have time measures?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM