Oracle XSLT:默认名称空间导致空标签 [英] Oracle XSLT: default namespace results in empty tags

查看:93
本文介绍了Oracle XSLT:默认名称空间导致空标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为问这个问题的最佳方法是:如何为输出中的根元素指定默认名称空间?这样做:

I think the best way to ask this question is: How do I specify a default namespace for the root element in the output? Doing this:

<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错误:

Gives me an error in 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"/>
                ...

我希望生成的文档的根元素看起来像这样:

I want the resulting document to have the root element look like this:

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

我希望"http://www.mycompany.com/default/schema"作为默认名称空间,以便文档可以通过XSD验证.否则,我必须在运行验证之前手动添加它(不是批处理的选项).

I want "http://www.mycompany.com/default/schema" as the default namespace so the document can pass XSD validation. Otherwise, I have to add it manually before running validation (not an option for batch processing).

编辑

我已经尝试过了:

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

结果是一个没有数据的文档,像这样:

The result is a document with no data, like this:

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

更新

源数据看起来像这样(我得到的输入中没有定义名称空间):

Source data looks something like this (input that I get has no namespaces defined in it):

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

推荐答案

有很多可能的解决方案,但是从PL/SQL来看,在Oracle中似乎没有一个很好的解决方案.这里的其他一名开发人员通过将XML对象转换为CLOB,执行一些字符串操作以将默认名称空间强制为根元素,然后再转换回XML以进行下一步来解决"这一问题……喜欢它,但是可以用...

There are many possible solutions, but none seem to work well in Oracle, from PL/SQL. One of the other devs here "solved" this by converting the XML object to a CLOB, performing some string manipulation to force the default namespace into the root element, and then converting back to XML for the next step... I don't like it but it works...

这篇关于Oracle XSLT:默认名称空间导致空标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆