You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSLT样式表无法生效,已尝试多种方法寻求帮助

解决XSL样式表不生效的问题

你的XSL代码存在多处语法错误,导致浏览器无法正确解析样式表,因此XML直接显示原始内容。以下是具体问题和修正方案:

1. XSL命名空间错误

原代码中命名空间地址缺失必要符号:

xmlns:xsl="http://www.w3org1999/XSL/Transform"

修正后:

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

2. <xsl:sort>标签语法错误

  • order="ascending"未闭合引号
  • select路径写错,应为seller_info/seller_name而非seller_info_seller_name
  • <xsl:sort>需嵌套在<xsl:apply-templates>内部,不能单独放置

3. <xsl:value-of>拼写错误

原代码写成<xsl:value of>,缺少连字符,属于XSL核心语法错误。

4. 模板标签结构错误

原代码中<xsl:apply-templates>出现多余闭合标签,导致结构不匹配。


修正后的完整XSL代码

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <head>
                <link href="CSSStyle.css" rel="stylesheet" type="text/css"/>
            </head>
            <body>
                <xsl:apply-templates select="/root/listing">
                    <xsl:sort select="seller_info/seller_name" order="ascending"/>
                </xsl:apply-templates>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="listing">  
        <div class="seller">
            <xsl:value-of select="seller_info/seller_name"/> (<xsl:value-of select="seller_info/seller_rating"/>)
        </div>
    </xsl:template>
</xsl:stylesheet>

额外提醒

你提供的XML代码片段存在未闭合标签(如<auction_info>、<listing>、<root>),虽然浏览器可能容错,但建议确保XML结构完整,避免潜在解析问题。

内容的提问来源于stack exchange,提问作者WJC1981

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 12:35:23