使用XSLT在Firefox和IE中进行XML到XML的转换 [英] XML to XML transformation with XSLT in Firefox and IE

查看:239
本文介绍了使用XSLT在Firefox和IE中进行XML到XML的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了从少数XML格式到一个标准的转换。
我的XSL看起来像下面的一样:

I did a transformation from few XML formats to one standard. My XSL looks like following one:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>

    <xsl:template match="list | store">
        <list>
            <xsl:for-each select="item | product | product-store">
            <item>
                <name>
                    <xsl:choose>
                        <xsl:when test="name"><xsl:value-of select="substring-before(name, ' ')" /></xsl:when>
                        <xsl:otherwise><xsl:value-of select="name | title" /></xsl:otherwise>
                    </xsl:choose>
                </name>
                <desc>
                    <xsl:choose>
                        <xsl:when test="name"><xsl:value-of select="substring-after(name, ' ')" /></xsl:when>
                        <xsl:otherwise><xsl:value-of select="desc" /></xsl:otherwise>
                    </xsl:choose>
                </desc>
                <nr><xsl:value-of select="index | number" /></nr>
            </item>
            </xsl:for-each>
        </list>
    </xsl:template>
</xsl:stylesheet>

我的示例XML是

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
<list>
    <item>
      <index>1362242627</index>
      <name>test 22</name>  
    </item>
    <item>
      <index>2362625609</index>
      <name>test 4</name>  
    </item>
    <item>
      <index>736274650</index>
      <name>test 76</name>  
    </item>
</list>

为什么在Firefox 17,IE9和Google Chrome等浏览器中无法正确显示?它们像普通文本一样显示它,但返回类型是text / xml。
在Opera只能正常工作。

Why doesn't it display correctly in browsers like Firefox 17, IE9 and Google Chrome? They display it like a normal text, however the return type is "text/xml". It works correctly in Opera only.

推荐答案

我认为问题是告诉什么是 。浏览器像Firefox或IE假设一旦你加载一个XML文档与 xml-stylesheet 处理指令类型 text / xsl 转换为浏览器窗口,您希望将XML转换为浏览器知道要呈现的东西,比如HTML,或者像今天像(X)HTML加SVG(或加MathML)。然而,您的样式表将使用XML输入并将其转换为浏览器未知的某些XML结果格式,因此它所做的是在结果树中呈现文本节点的内容。 Opera似乎将XML输入转换为XML结果,但是似乎认为结果格式是未知的,并且这种方式决定渲染结果的源树。这可能是你喜欢的,但我不知道有一个规范要求的行为。

I think the problem is to tell what is the "correct" display. Browsers like Firefox or IE assume that once you load an XML document with an xml-stylesheet processing instruction of type text/xsl into a browser window you want to transform the XML to something the browser knows to render, like HTML or these days like (X)HTML plus SVG (or plus MathML). Your stylesheet however takes the XML input and transforms it to some XML result format which is unknown to the browser so all it does is render the contents of text nodes in the result tree. Opera seems to transform the XML input to the XML result but then it seems to recognize that the result format is unknown and that way decides to render the source tree of the result. That might be what you prefer but I am not sure there is a spec demanding that behaviour.

这篇关于使用XSLT在Firefox和IE中进行XML到XML的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆