tags:

views:

128

answers:

3

I am generating and validating XML and am experiencing a problem where Oracle expands the full namespace from the prefix. The source document may look like this:

<pcy>
  <tList>
    <currTrn>
      <TXN_A>1</TXN_A>
      <TXN_B>2</TXN_B>
      ...

the transform looks like this:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sc="http://www.myCompany.com/schemaAlpha" xmlns:pl="http://www.myCompany.com/schemaBeta"&gt;
    <xsl:template match="/">
        <pcyItem>
            <pl:mainTList>
                <pl:currentTrnItem>
                    <sc:primaryTrnID>
                        <xsl:value-of select="/pcy/tList/currTrn/TXN_A"/>
                    </sc:primaryTrnID>
                    <sc:secondaryTrnID>
                        <xsl:value-of select="/pcy/tList/currTrn/TXN_B"/>
                    </sc:secondaryTrnID>
                                        ...

The correct output that I expect (and which I get when I use programs like JEdit - which has an XML transform plugin) looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<pcyItem xmlns:pl="http://www.myCompany.com/schemaAlpha" xmlns:sc="http://www.myCompany.com/schemaBeta"&gt;
    <pl:mainTList>
        <pl:currentTrnItem>
            <sc:primaryTrnID>1</scom:primaryTrnID>
            <sc:secondaryTrnID>2</scom:secondaryTrnID>
                        ...

What Oracle actually produces looks something like this:

<pcyItem>
  <pl:mainTList xmlns:pl="http://www.myCompany.com/schemaAlpha"&gt;
    <pl:currentTrnItem>
      <sc:primaryTrnID xmlns:sc="http://www.myCompany.com/schemaBeta"&gt;1&lt;/sc:primaryTrnID&gt;
      <sc:secondaryTrnID xmlns:sc="http://www.myCompany.com/schemaBeta"&gt;2&lt;/sc:secondaryTrnID&gt;
      ...

It looks to me like Oracle is "inlining" or expanding all of the namespace prefixes. Why is it doing this and how can I get it to stop?

A: 

Just guessing but it looks like Oracle implicitly sets

exclude-result-prefixes="pl sc"

I would try setting

exclude-result-prefixes="#default"

to override a possible implicit exclude.

Filburt
I tried adding `exclude-result-prefixes="#default"` to the `xsl:stylesheet` element, and now I get error `LPX-00601`: Oracle tells me that `#default` is an invalid token.
FrustratedWithFormsDesigner
By the way, when I tried setting `exclude-result-prefixes="pl sc"` (just to see what would happen), I was given a document with a single node (and nothing else): `<pcyItem/>`.
FrustratedWithFormsDesigner
So a little more research has led me to believe that `#default` is a part of XSL 2.0. I set `version="2.0"` but I still get an invalid token error. There must be something else I'm missing...
FrustratedWithFormsDesigner
A: 

Another way of looking at this is: Do you need to stop the Oracle processor doing this?

The output examples are semantically identical from pcyItem onwards, so presumably its just 'looking nice' that is concerning you. The Oracle processor is choosing to only declare namespaces at the point which they are needed rather than making them available throughout the document. It could be argued that this more specific scoping is better, but I guess it comes down to a matter of taste. I doubt there is anything you can do about it.

Anything consuming the output from the transformation, other than a human, won't care which form it reads so its probably not worth worrying about too much.

Andy
You're right that it's semantically identical, but not "looking nice" makes this output harder to debug, and at this point, debugging is still mostly manual (but that will probably change in the next week or so).
FrustratedWithFormsDesigner
A: 

Managed to fix it by changing the XSL:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    <xsl:template match="/">
        <pcyItem xmlns:sc="http://www.myCompany.com/schemaBeta" xmlns:pl="http://www.myCompany.com/schemaAlpha"&gt;
          ...
FrustratedWithFormsDesigner