例子15.18:在属性值里使用命名空间前缀的XML文档
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg"> <xsl:template match="svg:rect"> <rectangle><xsl:apply-templates/></rectangle> </xsl:template> </xsl:stylesheet>
你可以通过addNamespaceDeclaration()方法添加额外的命名空间绑定.如果需要,也可以通过removeNamespaceDeclaration()方法删除.
public Element addNamespaceDeclaration(Namespace namespace);
public Element removeNamespaceDeclaration(Namespace namespace);
例如这个代码片段可以生成xsl:stylesheet元素并且添加SVG命名空间去声明它.
Element stylesheet = new Element( "stylesheet", "xsl", "http://www.w3.org/1999/XSL/Transform"); Namespace svg = Namespace.getNamespace("svg", "http://www.w3.org/2000/svg"); stylesheet.addNamespaceDeclaration(svg);