XSLT:如何找到最后的文本空间,而不是前面有'sup‘标记的注释
嗨,即使在注释文本之后,我的xslt代码也在插入。如何避免这种情况。通过我的编码,我得到了第一段中的三个标签,要求是bk应该在'Profiling (REP‘)。请建议一下。
XML:
<article>
<para>Entiostats <!--td:require-hands --><!--ti-->require hands <!--/ti-->on work. This shows that Real-time Electrochemical Profiling (REP<sup>1</sup>).</para>
<para>Entiostats require hands <!--/ti-->on work. This shows that Real-time Electrochemical Profiling (REP<sup>1</sup>).</para>
<para>Entiostats require hands on work. This shows that Real-time Electrochemical Profiling (REP<sup>1</sup>).</para>
</article>XSLT:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()[following-sibling::*[1][name()='sup' or name()='inf']][not(parent::cross-ref) and not(parent::cross-refs)]">
<xsl:variable name="varTextBeforeSUP">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:for-each select="tokenize($varTextBeforeSUP,' ')">
<xsl:choose>
<xsl:when test="position()=last()">
<xsl:text disable-output-escaping="yes"><</xsl:text>?bk1?<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/><xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>要求:
<?xml version="1.0" encoding="UTF-8"?><article>
<para>Entiostats <!--td:require-hands --><!--ti-->require hands <!--/ti-->on work. This shows that Real-time Electrochemical Profiling <?bk1?>(REP<sup>1</sup>).</para>
<para>Entiostats require hands <!--/ti-->on work. This shows that Real-time Electrochemical Profiling <?bk1?>(REP<sup>1</sup>).</para>
<para>Entiostats require hands on work. This shows that Real-time Electrochemical Profiling <?bk1?>(REP<sup>1</sup>).</para>
</article>发布于 2014-06-24 12:04:10
你快到了。问题是表达的这一部分..。
<xsl:template match="text()[following-sibling::*[1][name()='sup' ...这是匹配的文本,其中的第一个元素是sup,但这并不意味着它是最直接的同级。执行*将忽略可能首先出现的文本(或注释)节点
试一试:
<xsl:template match="text()[following-sibling::node()[1][name()='sup' ...顺便说一下,如果您想输出<?bk1?>,那么不要这样做.
<xsl:text disable-output-escaping="yes"><</xsl:text>?bk1?<xsl:text disable-output-escaping="yes">></xsl:text>取而代之的是这样做:
<xsl:processing-instruction name="bk1" />https://stackoverflow.com/questions/24386040
复制相似问题