【发布时间】:2013-01-21 12:36:39
【问题描述】:
我是 xslt 的新手,我正在做一个聊天应用程序,我想将用户会话保存为 xml 文件,这些文件以用户预定义的颜色和字体出现,所以我使用 xslt 来实现这一点,但我没有知道如何从 xml 中获取字体并将其应用到 html 标记中,以便它与用户选择的字体一起显示。
<xsl:choose>
<xsl:when test="/body/msg[italic/text()='true']">
<i>
<font family="/body/msg[font/text()] color="/body/msg/color">
<xsl:value-of select="from" /><p>: </p>
<xsl:value-of select="content"/><br/>
</font>
</i>
</xsl:when>
<xsl:when test="/body/msg[bold/text()='true']">
<b>
<font family="/body/msg[font/text()]" color="/body/msg/color">
<xsl:value-of select="from" /><p>: </p>
<xsl:value-of select="content"/><br/>
</font>
</b>
</xsl:when>
<xsl:when test="/body/msg[bold/text()='true'] and /body/msg[italic/text()='true']">
<b>
<i>
<font family="/body/msg[font/text()]" color="/body/msg/color">
<xsl:value-of select="from" /><p>: </p>
<xsl:value-of select="content"/><br/>
</font>
</i>
</b>
</xsl:when>
</xsl:choose>
【问题讨论】:
-
使用 XSLT 生成具有演示意识的 HTML 会让您非常孤独。如果您希望生成用户可选择的主题,您应该使用 CSS,无论是从具有一致标记的 XSLT 生成,还是使用通过转换附加的外部文件中的预定义类。