Namespaces in XSLT

只愿长相守 提交于 2019-12-10 20:24:44

问题


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 currently 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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5873954/namespaces-in-xslt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!