简体   繁体   English

在XSL样式表标签中删除XSL名称空间前缀

[英]Dropping the XSL namespace prefix in XSL Stylesheet Tags

Is possible to drop the xsl: to XSL tags in XSL Stylesheets? 是否可以将xsl:放到XSL样式表中的XSL标签上?

For example, could: 例如,可以:

<xsl:if test=''>

be typed as: 输入为:

<if test=''>

Edit: Stylesheet has HTML and XML nodes within it. 编辑:样式表中具有HTML和XML节点。

Thanks, Ross 谢谢罗斯

Indeed you can do this, by defining the XSLT ("http://www.w3.org/1999/XSL/Transform") namespace as the default namespace: 实际上,您可以通过将XSLT(“ http://www.w3.org/1999/XSL/Transform”)命名空间定义为默认命名空间来做到这一点:

 <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform">
    ...
 </stylesheet>

The downside is that you then must use another prefix for your "domain" namespaces: 缺点是您必须为“域”名称空间使用另一个前缀:

 <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://whatever" xmlns:html="http://www.w3.org/1999/xhtml">
    <template match="foo:bar">
       <html:form>
           ...
       </html:form>
    </template>
 </stylesheet>

Sure you can, but combining @ysdx and @Jon's answers, beware that your XSLT processor needs to differentiate between XSLT elements and output elements. 当然可以,但是将@ysdx和@Jon的答案结合在一起,请注意您的XSLT处理器需要区分XSLT元素和输出元素。 For example, the following stylesheet throws an error in Firefox: 例如,以下样式表在Firefox中引发错误:

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
    <template match="/">
        <!-- <b> is not a valid XSLT element -->
        <b><value-of select="'test'"/></b>
    </template>
</stylesheet>

Which means you need to qualify the names of output elements, like this: 这意味着您需要限定输出元素的名称,如下所示:

<stylesheet version="1.0" 
         xmlns="http://www.w3.org/1999/XSL/Transform"
         xmlns:test="http://whatever">
    <template match="/">
        <test:b><value-of select="'test'"/></test:b>
    </template>
</stylesheet>

This can be problematic. 这可能是有问题的。 You should stick to the conventional xsl prefix, unless you can think of a good reason not to. 您应该坚持使用常规的xsl前缀,除非您有充分的理由不这样做。

Don't think so. 不要这样 They differentiate between the "language" and any nodes that are intended for output. 它们区分“语言”和打算输出的任何节点。

Yes. 是。

But do note that this has nothing to do with XSLT itself but with XML Names. 但是请注意,这与XSLT本身无关,而与XML名称无关。 That's why there are differences between XML 1.0 and XML 1.1 usage. 这就是XML 1.0和XML 1.1使用之间存在差异的原因。

As example, here you have some of my previus answers using this syntax: 举例来说,在这里,您可以使用以下语法获得一些先前的答案:

using xml as xsl variable 使用xml作为xsl变量

XSLT multiple string replacement with recursion XSLT递归替换多字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM