Html 将最后一个空间从混合内容节点移动到外部节点
我有大量由微软Word创建的HTML文件。我试图操纵这些文件的内容来提取数据等等 HTML段落包含混合内容,我发现斜体字或粗体字后的空格通常也是斜体字。当IHtml 将最后一个空间从混合内容节点移动到外部节点,html,xml,xslt,Html,Xml,Xslt,我有大量由微软Word创建的HTML文件。我试图操纵这些文件的内容来提取数据等等 HTML段落包含混合内容,我发现斜体字或粗体字后的空格通常也是斜体字。当Inormalize-space()稍后执行此操作时,空间将被剥离,不应连接的单词将被连接 <p>Some text here and some <i>italicized </i>text here.</p> 这里有一些文本,这里有一些斜体文本 后来的转换导致这种情况变得更加严重 <p
normalize-space()
稍后执行此操作时,空间将被剥离,不应连接的单词将被连接
<p>Some text here and some <i>italicized </i>text here.</p>
这里有一些文本,这里有一些斜体文本
后来的转换导致这种情况变得更加严重
<p>Some text here and some <i>italicized</i>text here.</p>
这里有一些文本,这里有一些斜体文本
(我在简化一些事情。)
我想和你在一起
<p>Some text here and some <i>italicized</i> text here.</p>
这里有一些文本,这里有一些斜体文本
我想确定元素中最后一个节点是以空格结尾的文本节点的情况,去掉尾随空格,并在元素后面添加空格
我想我可以拼凑一些东西,但是XQuery越来越复杂,我不得不想有一个更简单的方法。(可能没有,但如果我不问,我会很傻……)
看起来很近,但不是很近。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--Match the elements who's last child node is a text() node
that ends with a space. -->
<xsl:template match="*[node()[last()]
[self::text()[substring(.,string-length())=' ']]]">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<!--add the extra space following the matched element-->
<xsl:text> </xsl:text>
</xsl:template>
<!--Match the text() node that is the last child node of an element
and ends with a space -->
<xsl:template match="*/node()[last()]
[self::text()[substring(., string-length())=' ']]">
<!--remove the trailing space-->
<xsl:value-of select="substring(., 0, string-length())"/>
</xsl:template>
</xsl:stylesheet>