我正在使用 XForms 构建一个以 XML-DB eXist-db 作为后端的 Web 应用程序。eXist 将 XForms 代码转换为 HTML 和 JavaScript。
首先,我有两个实例:
<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>
我想构建一个表xf:repeat
来遍历<ServiceDefinition>
“结果”实例中的所有元素。每行都包含一个“状态”列,我想在其中放置“域”实例中的相关“状态”信息。
这是该表的 XForms 代码:
<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>
问题似乎是这部分:
<td>
<xf:output ref="instance('domain')/system[@name = instance('results')/result/ServiceDefinition[index('link-repeat')]/SystemName]/NIC/@state" />
</td>
这个表达有问题吗?我想在repeat语句中获取与当前节点匹配的系统状态属性。但是,当我加载页面并且“结果”实例包含许多项目时,我收到 Javascript 错误:
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*
行(在本例中为 771)总是不同的。
当结果实例非常小(最多大约 20 个元素)时,它会按预期工作。
任何帮助或建议表示赞赏,我对这一切都很陌生,所以请耐心等待。