【发布时间】:2021-08-10 22:22:49
【问题描述】:
XSLT:需要帮助如何将新属性(id)添加到将包含增量值的现有元素(行)。
输入:
<?xml version="1.0" encoding="UTF-8"?>
<Personal>
<description />
<details />
<information>
<Table>
<Location>
<location>town</location>
<location>city</location>
<location>country</location>
</Location>
<Contact>
<row>
<values>
<ref id="0" value="name" />
<ref id="1" value="address" />
</values>
</row>
<row>
<values>
<ref id="0" value="name" />
<ref id="1" value="" />
<ref id="2" value="" />
</values>
</row>
</Contact>
</Table>
</information>
</Personal>
期望的输出:
在行元素中有一个 id 属性,其中值将从 0 开始递增
<?xml version="1.0" encoding="UTF-8"?>
<Personal>
<description />
<details />
<information>
<Table>
<Location>
<location>town</location>
<location>city</location>
<location>country</location>
</Location>
<Contact>
<row id="0">
<values>
<ref id="0" value="name" />
<ref id="1" value="address" />
</values>
</row>
<row id="1">
<values>
<ref id="0" value="name" />
<ref id="1" value="" />
<ref id="2" value="" />
</values>
</row>
</Contact>
</Table>
</information>
</Personal>
我是 XSLT 的新手,我尝试的所有方法似乎都不起作用
【问题讨论】:
-
输入是否可以包含多个
Contact元素?如果是,row号码是否应该重新启动? -
只有一个联系人元素。无论如何,这已经解决了:)
-
不要告诉我们您尝试了所有方法但没有任何效果。告诉我们你尝试过的一件事,并告诉我们它是如何失败的。这样我们就可以看到您做错了什么,并帮助您提高学习曲线。
标签: xml xslt attributes increment