我认为提出这个问题的最好方法是:如何为输出中的根元素指定默认命名空间?这样做:
<xsl:template match="/">
<r xmlns:s"http://www.mycompany.com/s/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.mycompany.com/default/schema" >
....
....
Oracle 中出现错误:
ORA-31011: XML Parsing Failed
ORA-19201: Error occurred in in XML Processing
LPX-00604: Invalid attribute 'nIfNotExist', for attribute 'name'
ORA-06512: at SYS.XMLType at line 74
ORA-06512: at line 24
哪里的'nIfNotExist'
是一个模板:
<xsl:template name="nIfNotExist" xmlns:scom="http://www.mycomapny.com/s/schema">
<xsl:param name="nodeToTest"/>
<xsl:param name="nodeName"/>
...
我希望生成的文档的根元素如下所示:
<r xmlns:s="http://www.mycompany.com/s/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.mycompany.com/default/schema">
I want "http://www.mycompany.com/default/schema"
作为默认命名空间,因此文档可以通过 XSD 验证。否则,我必须在运行验证之前手动添加它(不是批处理的选项)。
EDIT
我已经尝试过这个:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:s="http://www.mycompany.com/schema"
xmlns="http://www.mycompany.com/def_schema">
结果是一个没有数据的文档,如下所示:
<r xmlns:s="http://www.mycompany.com/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.mycompany.com/def_schema">
<a></a>
<s:b></s:b>
<c></c>
....
本来应该是:
<r xmlns:s="http://www.mycompany.com/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.mycompany.com/def_schema">
<a>123</a>
<s:b>ABC34L</s:b>
<c>7.092381</c>
UPDATE
源数据看起来像这样(我得到的输入没有定义名称空间):
<ROOT_NODE>
<DATA_A>1234</DATA_A>
<DATA_B>34567</DATA_B>
<OTHER_DATA_C>7.123456</OTHER_DATA_C>
</ROOT_NODE>
所需输出
<r xmlns:s="http://www.mycompany.com/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.mycompany.com/def_schema">
<a>1234</a>
<s:b>34567</s:b>
<c>7.123456</c>
</r>