我想在xslt 1.0 中使用正则表达式
输入
<book>
<p>
The clavicle is broken more <inlinegraphic></inlinegraphic>
mad_2235.eps often than any other bone in the body
</p>
</book>
输出
<book>
<p>
The clavicle is broken more
<graphic name="mad_2235.eps" source="ISBN" in-line="yes"/>
often than any other bone in the body
</p>
</book>
谢谢,Muthu
XSLT1.0不做正则表达式,但我认为在这种情况下不需要它们。我会从身份转换开始
<!-- copy everything from input to output verbatim, except where overridden
by more specific templates -->
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
</xsl:template>
然后用一个模板覆盖它,该模板匹配紧跟在inlinegraphic
元素后面并包含.eps
的任何文本节点
<xsl:template match="text()[preceding-sibling::node()[1][self::inlinegraphic]]
[contains(., '.eps')]">
<!-- take everything before the first .eps as the graphic name -->
<graphic name="{normalize-space(substring-before(., '.eps'))}.eps"
source="ISBN" in-line="yes"/>
<!-- and leave everything after that as normal text -->
<xsl:value-of select="substring-after(., '.eps')" />
</xsl:template>
最后添加一个模板来删除inlinegraphic
元素本身
<xsl:template match="inlinegraphic" />