这里有一个适合你XSLT大师:-)
我必须处理Java程序我无法控制XML输出。
在这个输出的文档应用的HTML标签仍为
<u><i><b><em>
等等,而不是
<u><i><b><em> and so on.
这不是一个大问题,我使用XSLT来解决这个问题,但使用正常化空间以去除多余的空格这些HTML标签之前还删除空格。
例
<Locator Precode="7">
<Text LanguageId="7">The next word is <b>bold</b> and is correctly spaced
around the html tag,
but the sentence has extra whitespace and
line breaks</Text>
</Locator>
如果我运行XSLT脚本中,我们用它来去除多余的空白,这是其中的相关部分
<xsl:template match="text(.)">
<xsl:value-of select="normalize-space()"/>
</xsl:template>
在输出结果的XSLT已正确删除多余的空格和换行,但也去掉造成这种输出的标签之前的空间: -
The next word isboldand is correctly spaced around the html tag, but the sentence has extra whitespace and line breaks.
间距之前和之后单词“大胆”已被剥离为好。
任何人有任何想法如何防止这种情况发生? 非常好,在我束手无策,因此任何帮助,将不胜感激!
:-)
你好,我们又见面了,
是的,当然,这里是完整的样式表。 我们必须应对一个合格的HTML标签和间距
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no" encoding="UTF-8"/>
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Text//*">
<xsl:value-of select="concat('<',name(),'>')" />
<xsl:apply-templates />
<xsl:value-of select="concat('</',name(),'>')" />
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
<xsl:template match="Instruction//*">
<xsl:value-of select="concat('<',name(),'>')" />
<xsl:apply-templates />
<xsl:value-of select="concat('</',name(),'>')" />
</xsl:template>
<xsl:template match="Title//*">
<xsl:value-of select="concat('<',name(),'>')" />
<xsl:apply-templates />
<xsl:value-of select="concat('</',name(),'>')" />
</xsl:template>
</xsl:stylesheet>