【发布时间】:2018-02-14 03:50:51
【问题描述】:
这里是xml:
<?xml version="1.0" encoding="UTF-8"?>
<file>
<text>
<p>
<sentence>I bought <fruit>kiwi</fruit> at the grocery store.</sentence>
<sentence>I also bought <fruit>bananas</fruit> at the store.</sentence>
<sentence base="basket">Then, I bought a basket at another store.</sentence>
<sentence>You bought <fruit>peaches</fruit> at the grocery store.</sentence>
<sentence>You also bought <fruit>apples</fruit> at the store.</sentence>
<sentence>he bought <fruit>pears</fruit> at the grocery store.</sentence>
<sentence base="basket">Then, You bought a <fruit>oranges</fruit> and a basket at another store.</sentence>
<sentence>He also bought <fruit>lemons</fruit> at the store.</sentence>
</p>
</text>
</file>
这里是需要修改的xslt:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:template>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="file/text/p/sentence[fruit]”/>
</body>
</html>
</xsl:template>
<xsl:template match="sentence[fruit]”>
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
</xsl:stylesheet>
我需要计算 <fruit> 和之前和之后的 <sentence base="basket"> 之间的句子数。例如,<fruit>apples</fruit> 在 <sentence base=“basket”> (-2) 之后是两个 <sentence>,在另一个 <sentence base=“basket”> (+2) 之前是两个 <sentence>,而 <fruit>oranges</fruit> 在<sentence base=“basket”> (-0,+0)。
请帮忙。这是我需要的输出:
我在杂货店买了猕猴桃。(无,+2)
我也在商店买了香蕉。(无,+1)
你在杂货店买了桃子。 (-1, +3)
你还在商店买了苹果。 (-2, +2)
他在杂货店买了梨。 (-3, +1)
然后,你在另一家商店买了一个橙子和一个篮子。 (0,0)
他还在商店买了柠檬。 (-1,无)
【问题讨论】: