听起来你并不关心
p
元素的元素内容,除了想要使用i
元素将p
元素的内容拆分为两个字符串,组成为:
i
和i
...然后使用分隔符;
进一步
标记第二个字符串。
如果是这样的话,那么这样的事情对你有用:
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="p">
<xsl:copy>
<xsl:variable name="until-i" select="(i/preceding-sibling::node(), i)"/>
<xsl:variable name="after-i" select="i/following-sibling::node()"/>
<TypeA><xsl:value-of select="normalize-space(string-join($until-i))"/></TypeA>
<xsl:for-each select="tokenize(string-join($after-i), ';\s')">
<TypeB><xsl:value-of select="normalize-space(.)"/></TypeB>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
结果:
<?xml version="1.0" encoding="UTF-8"?>
<p>
<TypeA>Quantity:</TypeA>
<TypeB>250 mg</TypeB>
<TypeB>150</TypeB>
<TypeB>170</TypeB>
</p>