【发布时间】:2015-11-19 09:36:27
【问题描述】:
我正在使用 XSLT 进行 html 到 xml 的转换,在 html 输入中我有如下内容,
<p>An image outside a paragraph is placed into an <em>Element Image Frame</em>. If there are no (or not enough) <em>Element Image Frames</em> then the image is ignored and a warning is logged.</p>
使用 xsl,我需要的是,如果<em> 节点之前或之后有空格,这些节点应该替换为,<space/> 节点。所以预期的输出,
<p>An image outside a paragraph is placed into an<space/><Italic>Element Image Frame</Italic>. If there are no (or not enough)<space/><Italic>Element Image Frames</Italic><space/>then the image is ignored and a warning is logged.</p>
注意第一个<em>节点后面没有空格,所以没有添加<space/>。
我想我可以使用 XSLT 正则表达式,但我正在努力编写一个在 <em> 节点之前和之后选择两个空格的正则表达式。
<xsl:template match="p/text()">
<xsl:analyze-string select="." regex="^( )">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="regex-group(1)">
<space/>
</xsl:when>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
谁能给我建议一个方法来做到这一点..
【问题讨论】: