【发布时间】:2014-03-22 03:51:03
【问题描述】:
我在网上到处寻找这个问题的答案,但在任何地方都找不到。
我正在尝试构建一个使用XSLT 生成XML 数据的网络表单。我将它基于做同样事情的其他形式,并让小型测试结构正常工作。但是,当我尝试将其映射到重复元素时遇到了各种问题。
这里是我所拥有的快速概览。我有一个类似于此的XSLT 文件(免责声明:为简洁起见排除了行;此外,这些不是实际的字段名称):
<someForm:Name></someForm:Name>
<someForm:Address></someForm:Address>
<someForm:Plan>
<someForm:Step></someForm:Step>
<someForm:Description></someForm:Description>
</someform:Plan>
我还有一个如下所示的关联架构:
<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'”!这就是我遇到问题的地方!
我写了一个表格(同样,基于其他工作表格),如下所示:
<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。
但是,这是我的问题:我正在尝试编写我的设置,以便它最多可以容纳十行(根据 maxOccurs 设置)。当我尝试这样做时它不起作用:
<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>
这给了我各种各样的问题,这取决于我如何调整它。有时,它不保存任何数据(用于步骤和描述);有时,它会为两行保存相同的数据。
我找不到任何文档来解释它是如何工作的。我调整了XSLT、HTML 和schema,但都无济于事。这让我很沮丧。
有没有人知道如何解决这个问题?
注意:这与我之前提出的另一个问题直接相关:Creating XSLT nodes dynamically/multiple XSLT nodes
提前感谢您的帮助。 . .
【问题讨论】:
标签: xslt webforms xml-parsing xsd xml-serialization