如何为每一行应用标记
<预格式化>
GRANT JOHN阅读
EMP.SALARY
GRANT JOHN阅读
EMP.NAME
< /预格式化>
<预>
< code> GRANT JOHN READ< / code>
<代码> EMP.SALARY< /代码>
< code> GRANT JOHN READ< / code>
<代码> EMP.NAME< /代码>
< /预>
答案 0 :(得分:0)
预格式标记的内容将是单个文本块。传递给模板,substring-before($ text,' ')将为您提供第一行,然后使用substring-after调用相同的函数,直到它为空。
答案 1 :(得分:0)
在 XSLT 2.0
中你可以使用
<xsl:template match="preformat">
<pre>
<xsl:for-each select="tokenize(., '
')">
<xsl:if test="normalize-space(.) ne ''">
<code>
<xsl:value-of select="normalize-space(.)"/>
</code>
</xsl:if>
</xsl:for-each>
</pre>
</xsl:template>
您可以在http://xsltransform.hikmatu.com/eiQZDbh
看到此转化也适用于 XSLT 1.0
<xsl:template match="preformat">
<pre>
<xsl:call-template name="code">
<xsl:with-param name="data" select="."/>
</xsl:call-template>
</pre>
</xsl:template>
<xsl:template name="code">
<xsl:param name="data"/>
<xsl:choose>
<xsl:when test="contains($data, '
')">
<xsl:choose>
<xsl:when test="normalize-space(substring-before($data, '
')) = ''">
<xsl:if test="substring-after($data, '
')">
<xsl:call-template name="code">
<xsl:with-param name="data" select="substring-after($data, '
')"/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<code>
<xsl:value-of select="normalize-space(substring-before($data, '
'))"/>
</code>
<xsl:if test="substring-after($data, '
')">
<xsl:call-template name="code">
<xsl:with-param name="data" select="substring-after($data, '
')"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<code>
<xsl:value-of select="normalize-space($data)"/>
</code>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
看到转型