XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Bruce CantorSubject: Problem with namespace prefix in xquery
Author: Bruce Cantor
Date: 16 Dec 2021 09:46 AM
Originally Posted: 15 Dec 2021 11:11 AM
Hi

I have this weird issue with my xquery script.
The below script returns XML where the namespace prefixes are changed to weird generated namespace prefixes.
The result is valid, but is looking weird.
The namespace changes are located within the output for all elements included in the for loop, resulting in elements looking like this:

<ddtek-me1:DespatchLine xmlns:ddtek-me1="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
<ddtek-me2:DeliveredQuantity xmlns:ddtek-me2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" unitCode="STK">1</ddtek-me2:DeliveredQuantity>


This is the script:

declare namespace b = "urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2";
declare namespace a = "http://generic.xml.eetgroup.com";
declare namespace cbc = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2";
declare namespace cac = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2";

declare option ddtek:serialize 'indent=yes,omit-xml-declaration=no';


for $Dispatch in /a:DispatchAdvice/a:Dispatch
return
<b:DespatchAdvice xmlns:b="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
<cbc:CustomizationID>somthing</cbc:CustomizationID>
<cbc:ProfileID>gggggg</cbc:ProfileID>
<cbc:ID>TODO: dispatch ID missing from Generic file</cbc:ID>

<cbc:IssueDate>{ year-from-date(current-date())}-{ month-from-date(current-date())}-{ day-from-date(current-date()) }</cbc:IssueDate>

{
for $DispatchLine in $Dispatch/a:DispatchLines/a:DispatchLine
return
<cac:DespatchLine>
<cbc:DeliveredQuantity unitCode="{ $DispatchLine/a:UnitOfMeasure/text() }">
{ $DispatchLine/a:DeliveredQuantity/text() }
</cbc:DeliveredQuantity>
<cac:bcOrderLineReference>
<cbc:LineID>
{$DispatchLine/a:OrderLineReference/text() }
</cbc:LineID>
</cac:bcOrderLineReference>
<cac:Item>
<cbc:Description>
{ $DispatchLine/a:Item/a:Description/text() }
</cbc:Description>
<cac:SellersItemIdentification>
{ $DispatchLine/a:Item/a:VendorsItemNo/text() }
</cac:SellersItemIdentification>
<cac:ManufacturersItemIdentification>
<cbcID>
{ $DispatchLine/a:Item/a:ManufacturerPartNo/text() }
</cbcID>
</cac:ManufacturersItemIdentification>
<cac:StandardItemIdentification>
<cbc:ID>
{ $DispatchLine/a:Item/a:EAN/text() }
</cbc:ID>
</cac:StandardItemIdentification>
</cac:Item>
</cac:DespatchLine>
}

</b:DespatchAdvice>

Appreciating any input, thanks.


Unknownsample_shipment.xml
Conversion input

Postnext
Ivan PedruzziSubject: Problem with namespace prefix in xquery
Author: Ivan Pedruzzi
Date: 15 Dec 2021 04:52 PM
Bruce please attach an example of input document so we can test your query

Ivan Pedruzzi
Stylus Studio Team

Postnext
Bruce CantorSubject: Problem with namespace prefix in xquery
Author: Bruce Cantor
Date: 16 Dec 2021 09:47 AM
Originally Posted: 16 Dec 2021 09:48 AM
Hi Ivan.

I have uploaded an input file.
Kind regards
Bruce

Postnext
Ivan PedruzziSubject: Problem with namespace prefix in xquery
Author: Ivan Pedruzzi
Date: 20 Dec 2021 03:55 PM
You can obtain what you want avoiding to clash namespace prefixes

In the query prolog, you have the following definitions:

declare namespace cbc = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2";
declare namespace cac = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2";

The literal element has the same namespace definitions:

<b:DespatchAdvice
xmlns:b="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"


Simply renaming the namespace prefixes to cbc1, cac1 as following, prevents the XQuery engine to create additional namespace declarations in the query output

declare namespace cbc1 = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2";
declare namespace cac1 = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2";

In this specific query, you can safely remove the namespace declarations all together

Ivan Pedruzzi
Stylus Studio Team


declare namespace a = "http://generic.xml.eetgroup.com";
declare namespace b = "urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2";

(:
declare namespace cbc1 = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2";
declare namespace cac1 = "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2";
:)

declare option ddtek:serialize 'indent=yes,omit-xml-declaration=no';



for $Dispatch in /a:DispatchAdvice/a:Dispatch
return
<b:DespatchAdvice
xmlns:b="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
>
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
<cbc:CustomizationID>somthing</cbc:CustomizationID>
<cbc:ProfileID>gggggg</cbc:ProfileID>
<cbc:ID>TODO: dispatch ID missing from Generic file</cbc:ID>
<cbc:IssueDate>{ year-from-date(current-date()) }-{ month-from-date(current-date()) }-{ day-from-date(current-date()) }</cbc:IssueDate>
{
for $DispatchLine in $Dispatch/a:DispatchLines/a:DispatchLine
return
<cac:DespatchLine>
<cbc:DeliveredQuantity unitCode="{ $DispatchLine/a:UnitOfMeasure/text() }">
{ $DispatchLine/a:DeliveredQuantity/text() }
</cbc:DeliveredQuantity>
<cac:bcOrderLineReference>
<cbc:LineID>
{ $DispatchLine/a:OrderLineReference/text() }
</cbc:LineID>
</cac:bcOrderLineReference>
<cac:Item>
<cbc:Description>
{ $DispatchLine/a:Item/a:Description/text() }
</cbc:Description>
<cac:SellersItemIdentification>
{ $DispatchLine/a:Item/a:VendorsItemNo/text() }
</cac:SellersItemIdentification>
<cac:ManufacturersItemIdentification>
<cbcID>
{ $DispatchLine/a:Item/a:ManufacturerPartNo/text() }
</cbcID>
</cac:ManufacturersItemIdentification>
<cac:StandardItemIdentification>
<cbc:ID>
{ $DispatchLine/a:Item/a:EAN/text() }
</cbc:ID>
</cac:StandardItemIdentification>
</cac:Item>
</cac:DespatchLine>
}

</b:DespatchAdvice>

Posttop
Bruce CantorSubject: Problem with namespace prefix in xquery
Author: Bruce Cantor
Date: 21 Dec 2021 09:29 AM
Thanks, now I can see that I only need to declare the namespaces in the ingoing document.

/Bruce

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.