将 Web 表单数据映射到重复的 XML 元素 [英] Mapping web form data to repeated XML elements
问题描述
我在网上到处寻找这个问题的答案,但在任何地方都找不到.
I have gone all over the web looking for an answer to this, and have not been able to find one anywhere.
我正在尝试构建一个使用 XSLT
生成 XML
数据的 Web 表单.我把它建立在做同样事情的其他形式上,并且已经让小的测试结构正常工作.但是,当我尝试将其映射到重复元素时遇到了各种问题.
I'm trying to build a web form that uses XSLT
to generate XML
data. I'm basing it on other forms that do the same thing, and have gotten small test structures to work fine. However, I am running into all sorts of problems when I try to map it to repeated elements.
这是我所拥有的快速概览.我有一个与此类似的 XSLT
文件(免责声明:为简洁起见排除了行;此外,这些不是实际的字段名称):
Here's a quick overview of what I have. I have an XSLT
file that looks similar to this (disclaimer: lines excluded for brevity; also, these are NOT the actual field names):
<someForm:Name></someForm:Name>
<someForm:Address></someForm:Address>
<someForm:Plan>
<someForm:Step></someForm:Step>
<someForm:Description></someForm:Description>
</someform:Plan>
我还有一个关联的架构,如下所示:
I also have an associated schema that looks like this:
<xs:element name="Name" />
<xs:element name="Address" />
<xs:element name="Plan" maxOccurs="10">
<xs:complexType>
<xs:sequence>
<xs:element name="Step" />
<xs:element name="Description" />
</xs:sequence>
</xs:complexType>
</xs:element>
记下 Plan 元素中的maxOccurs='10'"!这就是我遇到问题的地方!
我写了一个看起来像这样的表单(同样,基于其他工作表单):
I wrote a form (again, based on other, working forms) that looks like this:
<input type="text" id="getName" xpath="/*[local-name()='Name']">
<input type="text" id="getAddress" xpath="/*[local-name()='Address']">
<table>
<tr><th>Step</th><th>Description</th></tr>
<tr>
<td><input type="text" id="getStep1" xpath="/*[local-name()='Plan']/*[local-name()='Step']"></td>
<td><input type="text" id="getDesc1" xpath="/*[local-name()='Plan']/*[local-name()='Description']"></td>
</tr>
</table>
这很好用;我可以提交数据,它会根据需要创建 XML.
This works fine; I am able to submit data, and it creates the XML as I want.
但是,这是我的问题:我正在尝试编写我的设置,以便它最多可以容纳十行(根据 maxOccurs 设置).当我尝试这样做时它不起作用:
However, here is my problem: I am trying to write my setup so it can accommodate up to ten rows (as per the maxOccurs setting). It will NOT work when I try to do this:
<tr>
<td><input type="text" id="getStep1" xpath="/*[local-name()='Plan']/*[local-name()='Step']"></td>
<td><input type="text" id="getDesc1" xpath="/*[local-name()='Plan']/*[local-name()='Description']"></td>
</tr>
<tr>
<td><input type="text" id="getStep2" xpath="/*[local-name()='Plan']/*[local-name()='Step']"></td>
<td><input type="text" id="getDesc2" xpath="/*[local-name()='Plan']/*[local-name()='Description']"></td>
</tr>
这给我带来了各种各样的问题,这取决于我如何调整它.有时,它不保存任何数据(对于步骤和描述);有时,它会为两行保存相同的数据.
This gives me all sorts of problems, depending on how I tweak it. Sometimes, it does not save any data (for Step and Description); sometimes, it saves the same data for both rows.
我找不到任何文档来解释它是如何工作的.我已经调整了 XSLT
、HTML
和 schema
,但都无济于事.这让我很沮丧.
I have not been able to find any documentation that explains how this works. I've tweaked the XSLT
, HTML
, and schema
, all to no avail. And this is frustrating the crap out of me.
有人知道如何解决这个问题吗?
Does anyone have any insight as to how to solve this?
注意:这与我之前提出的另一个问题直接相关:CreatingXSLT 节点动态/多个 XSLT 节点
Note: this is directly related to another question that I asked earlier: Creating XSLT nodes dynamically/multiple XSLT nodes
提前感谢您的任何帮助...
Thanks in advance for any assistance . . .
推荐答案
以下是我最终实现此功能的方法:
Here's how I finally got this to work:
<tr>
<td><input type="text" id="getStep1" xpath="/*[local-name()='Plan'][1]/*[local-name()='Step']"></td>
<td><input type="text" id="getDesc1" xpath="/*[local-name()='Plan'][1]/*[local-name()='Description']"></td>
</tr>
<tr>
<td><input type="text" id="getStep2" xpath="/*[local-name()='Plan'][2]/*[local-name()='Step']"></td>
<td><input type="text" id="getDesc2" xpath="/*[local-name()='Plan'][2]/*[local-name()='Description']"></td>
</tr>
如果您查看 xpath,请注意计划"之后的 [1] 和 [2].当我将它们包含在 xpath 中时,它没有问题.
If you look at the xpath, notice the [1] and [2] after "Plan." When I included those with the xpath, it worked with no problem.
这篇关于将 Web 表单数据映射到重复的 XML 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!