XSL / XSLT生成文本,<xsl:for-each>粗体</xsl:for-each>

时间:2011-02-10 14:43:53

标签: xml xslt

我有一个XSL模板,在其中,我需要一个粗体部分或至少一个较重的字体/较大的字体。

Your name -
    <xsl:for-each select="date">
    <xsl:value-of select="substring(.,1,25)"/>
    </xsl:for-each>

所以“你的名字”需要加粗,但动态生成的“日期”也是如此。

我已经尝试过将大胆的标签包裹起来等等,但要明白这不是XSL的真正作用。我找不到解决办法。提前谢谢。

3 个答案:

答案 0 :(得分:2)

可能是完整的例子可能会有帮助。

<强> XML:

<t>
    <date>2010-10-02</date>
    <date>2010-10-02</date>
    <date>2010-10-02</date>
    <date>2010-10-02</date>
    <date>2010-10-02</date>
    <date>2010-10-02</date>
</t>

<强> XSL:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>

    <xsl:template match="/t">
        <strong>
            <xsl:text>Your name - </xsl:text>
            <xsl:for-each select="date">
                <xsl:value-of select="substring(.,1,25)"/>
            </xsl:for-each>
        </strong>
    </xsl:template>     
</xsl:stylesheet>

输出为源代码(仅为清晰起见,换行符):

<strong>Your name - 
2010-10-022010-10-022010-10-022010-10-022010-10-022010-10-02</strong>

输出呈现:

您的姓名 - 2010-10-022010-10-022010-10-022010-10-022010-10-022010-10-02

答案 1 :(得分:0)

这将以HTML格式呈现吗?

我不是XSLT专家,但我认为包装粗体标签没有任何问题。

<h1>
Your name -
    <xsl:for-each select="date">
    <xsl:value-of select="substring(.,1,25)"/>
    </xsl:for-each>
</h1>

答案 2 :(得分:0)

我认为你的意思是:

Your name -
    <span style="font-weight:900">
       <xsl:for-each select="date">
          <xsl:value-of select="substring(.,1,25)"/>
       </xsl:for-each>
    </span>

900是最大值。 font-weight CSS属性还有很多其他可能的值。但是根据你的问题,我怀疑父元素中的font-weight正在影响整个摘录的呈现。

相关问题