XSLT 1.0:无法在 for-each 中使用变量,是否有其他方法来解决此示例?
我对 xslt 的可能性有疑问。下面可以用xslt来完成吗?
输入:`
<invoice>
<record><field>ROWORD;123;;;</field></record>
<record><field>ROWART;shoe;10,2;20;</field></record>
<record><field>ROWORD;124;;;</field></record>
<record><field>ROWART;ball;1,5;2;</field></record>
<record><field>ROWART;car;1000;1;</field></record>
<record><field>ROWART;tractor;900;2;</field></record>
<record><field>ROWORD;125;;;</field></record>
<record><field>ROWART;computer;100;200;</field></record>
<record><field>ROWART;shoes;10,2;20;</field></record>
<record><field>ROWORD;126;;;</field></record>
<record><field>ROWART;keyboard;100;1;</field></record>
</invoice>
输出应该是:
<article>
<description>shoe</description>
<price>10,2</price>
<ordernumber>123</ordernumber>
<article>
<description>ball</description>
<price>1,5</price>
<ordernumber>124</ordernumber>
<article>
<description>car</description>
<price>1000</price>
<ordernumber>124</ordernumber>
<article>
<description>tractor</description>
<price>900</price>
<ordernumber>124</ordernumber>
<article>
<description>computer</description>
<price>100</price>
<ordernumber>125</ordernumber>
<article>
<description>shoe</description>
<price>10,2</price>
<ordernumber>125</ordernumber>
<article>
<description>keyboard</description>
<price>100</price>
<ordernumber>126</ordernumber>
我使用了 for-each 来循环记录。然后我将标签字段拆分为单独的变量(使用前子串/后子串)。使用 if 语句,我检查标记字段是否以 ROWART 开头,但随后出现问题。我找不到找到响应订单号的方法。
所以,我正在寻找一种记住 ROWORD 的方法。
也许我使用xslt的想法有问题。 我使用 xslt 1.0。输入无法更改。
感谢您的帮助 奥利维尔
I have a question about the possiblities of xslt. Can following be done with xslt?
input:`
<invoice>
<record><field>ROWORD;123;;;</field></record>
<record><field>ROWART;shoe;10,2;20;</field></record>
<record><field>ROWORD;124;;;</field></record>
<record><field>ROWART;ball;1,5;2;</field></record>
<record><field>ROWART;car;1000;1;</field></record>
<record><field>ROWART;tractor;900;2;</field></record>
<record><field>ROWORD;125;;;</field></record>
<record><field>ROWART;computer;100;200;</field></record>
<record><field>ROWART;shoes;10,2;20;</field></record>
<record><field>ROWORD;126;;;</field></record>
<record><field>ROWART;keyboard;100;1;</field></record>
</invoice>
output should be:
<article>
<description>shoe</description>
<price>10,2</price>
<ordernumber>123</ordernumber>
<article>
<description>ball</description>
<price>1,5</price>
<ordernumber>124</ordernumber>
<article>
<description>car</description>
<price>1000</price>
<ordernumber>124</ordernumber>
<article>
<description>tractor</description>
<price>900</price>
<ordernumber>124</ordernumber>
<article>
<description>computer</description>
<price>100</price>
<ordernumber>125</ordernumber>
<article>
<description>shoe</description>
<price>10,2</price>
<ordernumber>125</ordernumber>
<article>
<description>keyboard</description>
<price>100</price>
<ordernumber>126</ordernumber>
I used a for-each to loop over the records. Then I split the tag field in seperate variables (with substring-before / substring-after). With the if statement I check if the tag field starts-with ROWART, but then I have a problem. I can't find a way to find the responding ordernumber.
So, i'm looking for a way to remember ROWORD.
Maybe there's something wrong with my idea of using xslt.
I use xslt 1.0. The input can't be changed.
Thanks for your help
Olivier
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只在 ROWART 项上使用 for-each,然后使用前面的-sibling::…ROWORD 来获取所需的额外数据怎么样?
就像这样:
What about just using a for-each on the ROWART items, and then the preceding-sibling::…ROWORD for the required extra data?
Like so: