开发者

Namespaces in XSLT

I'm learning how to do custom functions in XSLT. Every example I find seems to declare a custom namespace, e.g.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:mynamespace="http://whatever">

What I don't understand is what should go where I cu开发者_如何转开发rrently have 'http://whatever', and what does this do? Can't I use the default xsl namespace to make functions?

Thanks in advance for any help


From http://www.w3.org/TR/xslt20/#stylesheet-functions

Note:

The prefix must not refer to a reserved namespace: [see ERR XTSE0080]

From http://www.w3.org/TR/xslt20/#dt-reserved-namespace

Definition: The XSLT namespace, together with certain other namespaces recognized by an XSLT processor, are classified as reserved namespaces and must be used only as specified in this and related specifications.

From http://www.w3.org/TR/xslt20/#err-XTSE0080

It is a static error to use a reserved namespace in the name of a named template, a mode, an attribute set, a key, a decimal-format, a variable or parameter, a stylesheet function, a named output definition, or a character map.


If your stylesheet is throwaway code, use anything you like for the namespace for local functions. I sometimes use "http://localhost/", but I've also been known to use "my:functions". If the stylesheet is going to be seen or used by other people and the functions need to be reusable and documented, then think carefully about choosing a namespace that will be globally unique and reflects the design authority for the specification of the functions; most people choose something like http://your.domain.name/ns/purpose, and you might also consider putting a specification of the functions at that location on the web. Another convention, if your function library is closely associated with a particular XML vocabulary, and has the same design authority as that vocabulary, is to put the functions in the same namespace as the elements in that vocabulary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜