【问题标题】:Use formatting tags in XML在 XML 中使用格式化标签
【发布时间】:2015-07-11 21:55:39
【问题描述】:

以下是 XML 和 XSLT 文件的源代码,我得到的输出是“Bold Text Italics Text”,粗体和斜体格式标记被忽略。如何调整此代码以确保应用所有标签并且我的输出文本为粗体/斜体?

XML 文件 (text.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

<examples>
    <example><b>Bold Text</b> <i>Italics Text</i></example>
</examples>

XSL 文件 (test.xsl)

<xsl:template match="/">
    <html>
        <head>
            <title>Title</title>
        </head>
        <body>
            <xsl:value-of select="examples/example"/>
        </body>
    </html>
</xsl:template>

【问题讨论】:

    标签: html xml xslt tags formatting


    【解决方案1】:

    您应使用xsl:copy-of,因为输入格式是example 所期望的格式:

    <xsl:template match="/">
        <html>
            <head>
                <title>Title</title>
            </head>
            <body>
                <xsl:copy-of select="examples/example"/>
            </body>
        </html>
    </xsl:template>
    

    【讨论】:

    • 感谢您的回复,问题是它会将这些标签应用到整行,我需要加粗一半,下半部分需要斜体。
    • @Alex 因为你的输入 XML 有 &lt;b&gt;&lt;i&gt; 标签,我认为将 xsl:value-of 更改为 xsl:copy-of 对你有用。已更新我的答案。
    • 非常感谢,真不敢相信它这么简单。我一直在寻找几个小时。
    • @Alex 欢迎您!请您勾选正确的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 2013-07-04
    • 2013-12-28
    相关资源
    最近更新 更多