XSLT 身份转换 [英] XSLT identity transform

查看:28
本文介绍了XSLT 身份转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试 XSLT 身份转换,因此我在 www.w3schools.com 上随机选择了以下示例,因为它允许我在线尝试:

I was testing out XSLT identity transform and so I randomly chose the following example on www.w3schools.com because it allows me to try online:

http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_apply

我将右侧窗格中的 XSLT 更改为身份转换:

I changed the XSLT in the right pane to be identity transform:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>  
    </xsl:template>

</xsl:stylesheet>

并尝试了一下.我发现 /catalog/cd/title 节点不会被复制到输出中(但其他一切都会).如果我将名称从 /catalog/cd/title 更改为 /catalog/cd/title1(或任何其他名称),它会复制节点.

And tried it out. What I found was that the /catalog/cd/title nodes do not get copied into the output (but everything else does). If I change the name from /catalog/cd/title to /catalog/cd/title1 (or any other name) it does copy the node.

所以我想知道 www.w3schools.com 上的 XSLT 实现是否只是一个错误,或者 XML 节点标题"是否有一些特殊意义导致它不被复制?我正计划使用如上所述的 XSLT 转换,但我想确保我知道任何问题...

So I was wondering if there is just a bug in the XSLT implementation on www.w3schools.com or if there is some special significance to the XML node 'title' that causes it to not get copied? I'm planning on using the XSLT transform as described above, but I want to make sure I'm aware of any gotchas...

推荐答案

该 w3schools 工具可用于测试 XML 到 HTML 的转换,因为它尝试在浏览器中将转换结果呈现为 HTML.通过身份转换,您不会创建任何 HTML,而是创建 XML.只有转换结果中的title"元素在浏览器看来是一个已知但错误放置的 HTML 元素,因此它不会在页面中显示.所有其他元素都是未知的,因此会呈现其文本内容.

That w3schools tool is useful for testing XML to HTML transformation as it tries to render the transformation result as HTML in the browser. With your identity transformation you do not create any HTML but rather XML. Only the "title" element in the transformation result looks to the browser as a known but wrongly placed HTML element so it does not display it in the page. All other elements are unknown so their text contents is rendered.

基本上给自己一个独立的 XSLT 处理器或 XML 编辑器,w3schools 工具除了 XML 到 HTML 的转换之外,对于调试和测试任何东西都没有用.

Basically get yourself a standalone XSLT processor or an XML editor, that w3schools tool is not useful to debug and test anything but XML to HTML transformations.

这篇关于XSLT 身份转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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