This discussion is archived
9 Replies Latest reply: Jan 11, 2013 1:29 AM by Mani RSS

Problems with Spaces  in XQuery transformation

786406 Newbie
Currently Being Moderated
hi,

I am using Xquery to combine the tags of an XML A that has 4tags to form an XML B that has only one tag in it, and when there is value in all the tags of XML A then this transformation works fine,but the problem comes when there are spaces in one of the tags of XML A, because while transforming into XML B the spaces gets eaten up

eg.

XML A :

<?xml version="1.0"?>
<note>
<to>rahul</to>
<from> </from>
<heading>heading</heading>
<body>body_1</body>
</note>

after transformation

XML B:

<?xml version="1.0"?>
<data>
rahulheadingbody_1
</data>



kindly help!!

Regards
Rahul
  • 1. Re: Problems with Spaces  in XQuery transformation
    AbhishekJ Expert
    Currently Being Moderated
    Can you please post your XQuery.
    Also which platform you are running the XQuery on? (OSB, SOA Suite, Plain Java/J2EE App etc)

    This works just fine for me:

    XQuery:
    declare namespace xf = "http://tempuri.org/XQuery/otn/";
    
    declare function xf:ConcatContent($note as element(*))
    as element(*) {
    <data>{ fn:concat($note/to, $note/from, $note/heading, $note/body)}</data>
    };
    
    declare variable $note as element(*) external;
    
    xf:ConcatContent($note)
    Input:
    <?xml version="1.0"?>
    <note>
    <to>rahul</to>
    <from> </from>
    <heading>heading</heading>
    <body>body_1</body>
    </note>
    Output:
    <data>rahul headingbody_1</data>
  • 2. Re: Problems with Spaces  in XQuery transformation
    786406 Newbie
    Currently Being Moderated
    declare namespace ns0 = "http://www.example.org/data";
    declare namespace xf = "http://tempuri.org/OSB_Try/tagBreak/";

    declare function xf:tagBreak($note1 as element(note))
    *as element(ns0:data) {*
    *<ns0:data>*
    *<ns0:data1>{ concat($note1/to , $note1/from , $note1/heading , $note1/body) }</ns0:data1>*
    *</ns0:data>*
    *};*

    declare variable $note1 as element(note) external;

    xf:tagBreak($note1)


    and I am doing this on weblogic workshop right now but I would be using this for OSB eventually
  • 3. Re: Problems with Spaces  in XQuery transformation
    786406 Newbie
    Currently Being Moderated
    and I tried using your XQuery only buts that is also not working for me.
  • 4. Re: Problems with Spaces  in XQuery transformation
    odie_63 Guru
    Currently Being Moderated
    Hi,

    It appears that the default implementation you're using doesn't preserve whitespaces.

    Try adding this in the XQuery prolog :
    declare boundary-space preserve;
  • 5. Re: Problems with Spaces  in XQuery transformation
    786406 Newbie
    Currently Being Moderated
    I tried this but this is not working....but when I am trying to run the same Xquery in OSB its working....so i guess there is some problem with the test console of Xquery in Workshop for weblogic.
  • 6. Re: Problems with Spaces  in XQuery transformation
    AbhishekJ Expert
    Currently Being Moderated
    A bug is certainly a possibility!
    Which version of Weblogic Workshop and ALSB are you using? (OSB comes with OEPE and not Weblogic Workshop, ALSB used to come with WWorkshop).
    I tried on Weblogic Workshop for WLI 8.1.6 and it was working fine there.
    Anyways, as long as it is working correctly in OSB/ALSB you should not have any problems at runtime ;)
  • 7. Re: Problems with Spaces  in XQuery transformation
    768116 Newbie
    Currently Being Moderated
    Hi,

    I am facing a similar issue with regard to the spaces in xml generated by xquery in OSB 11g

    I have an xquery which generates an XMl, but in some tags, I find that, there are spaces and new line between the tags and the data i.e.

    my xquery snippet has this:

    <expression>{data($body/*[1])}</expression>

    and the resultant xml is:

    <expression>
    http://test/default
    </expression>

    instead of <expression>http://test/default</expression>.

    Does anyone have a solution, how I can trim the spaces between the tag and the data.


    Regards
    Kshama
  • 8. Re: Problems with Spaces  in XQuery transformation
    odie_63 Guru
    Currently Being Moderated
    Try with normalize-space() function :
    <expression>{normalize-space(data($body/*[1]))}</expression>
    Or just
    <expression>{normalize-space($body/*[1])}</expression>
  • 9. Re: Problems with Spaces  in XQuery transformation
    Mani Newbie
    Currently Being Moderated
    Hi All,
    I am also facing the same problem in XQ (OSB 11.1.1.5) ,in my XQ I used xml:space="preserve" like

    <text xml:space="preserve">{data($Test/value)}</text>,generated xml is failed while validating and I am getting the following exception,


    <con:fault xmlns:con="http://www.bea.com/wli/sb/context">
    <con:errorCode>BEA-382505</con:errorCode>
    <con:reason>OSB Validate action failed validation</con:reason>
    <con:details>
    <con1:ValidationFailureDetail xmlns:con1="http://www.bea.com/wli/sb/stages/transform/config">
    <con1:message>
    Attribute not allowed (no wildcards allowed): space@http://www.w3.org/XML/1998/namespace in element text
    </con1:message>
    <con1:xmlLocation/>

    It's very urgent requirement can any body help?

    Regards
    Mani

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points