虽然我有一个 xml 文件作为输入,例如:
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
</catalog>
我试图找到在文件中或在 xsl 本身中包含以下信息的最佳方法:
value to search for:
An in-depth look at creating applications with XML.
add location:
on the self
value to search for:
A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.
add location:
on the self
所以如果我制作了一个逗号分隔的输入文件,它看起来像:
"An in-depth look at creating applications with XML.","on the self"
"A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.","on the self"
我已经尝试过使用 xslt 2,但我不断收到错误,例如不允许多个项目的序列,因为变量 $search_phrase 的值...
期望的输出:
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>to be checked</description>
<location>on the self</location>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>to be checked</description>
<location>on the self</location>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
</catalog>
有人可以给我一个 xslt-3.0 的例子,我可能可以替换上述短语,并添加所需的元素,只要有匹配项?
我需要做什么:
在完整的 xml 文件中,有许多记录可以具有相同的描述。我还需要对描述进行完全匹配:不应匹配短语“深入了解使用 XML 创建应用程序,作者...”。在我的例子中,我也有一个描述,其中的区别只是这种情况,例如“深入了解使用 XML 创建应用程序”。不应该也匹配。因为在我的代码中我使用小写,这也可能是问题,但不确定......每当有匹配项时,必须将沿着搜索词指定的位置添加到 location 元素中,该元素目前不存在于任何记录在xml中。