Dropping the XSL namespace prefix in XSL Stylesheet Tags
Is possible to drop the xsl:
to XSL tags in XSL Stylesheets?
For example, could:
开发者_StackOverflow社区<xsl:if test=''>
be typed as:
<if test=''>
Edit: Stylesheet has HTML and XML nodes within it.
Thanks, Ross
Indeed you can do this, by defining the XSLT ("http://www.w3.org/1999/XSL/Transform") namespace as the default namespace:
<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. For example, the following stylesheet throws an error in 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.
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. That's why there are differences between XML 1.0 and XML 1.1 usage.
As example, here you have some of my previus answers using this syntax:
using xml as xsl variable
XSLT multiple string replacement with recursion
精彩评论