xslt:在子字符串后保留节点中的所有elemenent和标签

时间:2018-04-13 22:53:29

标签: xml xslt xpath

我需要匹配一个节点,并将其中一部分从特定字符串子串到节点的末尾 例如,在此代码中:

.........
<?xml version="1.0" encoding="utf-8" ?>
<body>
 <div class="todo">
  <p class="commission">1. shop at the <b>supermarket</b> when the weather <i>is nice</i></p>
  <p class="letter"><i>a)</i> buy chocolate <b>biscuits</b></p>
  <p class="number"><b>2.</b> after <red>doing</red> all the<blue>things</blue>, <i>go and refuel</i> the car</p>
 </div> 
</body>

我需要获得这样的输出,保留标签末尾点后面的空格:

<body>
 <parte>
  <num>1.</num>
  <p> shop at the <b>supermarket</b> when the weather <i>is nice</i></p>
 </parte>
 <parte>
  <num><i>a)</i></num>
  <p> buy chocolate <b>biscuits</b></p>
 </parte>
 <parte>
  <num><b>2.</b></num>
  <p> after <red>doing</red> all the<blue>things</blue>, <i>go and refuel</i> the car</p>
 </parte>
</body>

我试着用标准的substring-after或substring-before指令做但没有结果,我需要保留p标签内的所有节点

提前致谢

1 个答案:

答案 0 :(得分:1)

也许在substring()的第一个text()孩子身上执行p ...

<xsl:template match="p[@class=('commission','letter','number')]/text()[1]">
    <xsl:value-of select="substring-after(.,' ')"/>
</xsl:template>

更新了小提琴:Trying to use django and dropzone/