-2

我想在 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>

谢谢,穆图

4

1 回答 1

0

XSLT 1.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" />
于 2013-08-08T11:29:04.157 回答