Pradeep0308
asked on
XSLT Question
Hi,
We are sending the below SOAP response and there is a requirement where the <Message> needs to look like <Message xmlns="">
Note that the XSLT needs to be general as StockAdjustmentMsg can also be different like OrderMsg etc. Also Body can repeat.
Thanks
Pradeep
We are sending the below SOAP response and there is a requirement where the <Message> needs to look like <Message xmlns="">
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<StockAdjustmentMsg xmlns="http://www.abc-def.com/ns/schema">
<Message>
<Header>
<ApiVersion>1.0.1</ApiVersion>
<CreationTime>2014-07-18T11:30:17</CreationTime>
<SenderId>ABCD</SenderId>
<SenderAuth>18a51609-6ae2-4ea7-b5bd-bc8806fd</SenderAuth>
<ReceiverId>DEF</ReceiverId>
<MessageType>STOCK_ADJUSTMENT</MessageType>
</Header>
<Body>
<MessageId>20140718113017_</MessageId>
<StockAdjustment>
<ProductNr>60000000006902</ProductNr>
<Quantity>6</Quantity>
<StockTypeTo>NEW</StockTypeTo>
<Reason>510</Reason>
</StockAdjustment>
</Body>
</Message>
</StockAdjustmentMsg>
</soapenv:Body>
</soapenv:Envelope>
Note that the XSLT needs to be general as StockAdjustmentMsg can also be different like OrderMsg etc. Also Body can repeat.
Thanks
Pradeep
ASKER
Geert,
The output of the XSLT is below:
:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<StockAdjustmentMsg xmlns="http://www.abc-def.com/ns/schema">
<Message xmlns="">
<Header xmlns="http://www.abc-def.com/ns/schema">
<ApiVersion>1.0.1</ApiVers ion>
<CreationTime>2014-07-18T1 1:30:17</C reationTim e>
<SenderId>ABCD</SenderId>
<SenderAuth>18a51609-6ae2- 4ea7-b5bd- bc8806fd</ SenderAuth >
<ReceiverId>DEF</ReceiverI d>
<MessageType>STOCK_ADJUSTM ENT</Messa geType>
</Header>
<Body xmlns="http://www.abc-def.com/ns/schema">
<MessageId>20140718113017_ </MessageI d>
<StockAdjustment>
<ProductNr>60000000006902< /ProductNr >
<Quantity>6</Quantity>
<StockTypeTo>NEW</StockTyp eTo>
<Reason>510</Reason>
</StockAdjustment>
</Body>
</Message>
</StockAdjustmentMsg>
</soapenv:Body>
</soapenv:Envelope>
It is adding namespace to Header and Body also. I only need Message to look like <Message xmlns="">. Below is how I need the output to look like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<StockAdjustmentMsg xmlns="http://www.abc-def.com/ns/schema">
<Message xmlns="">
<Header>
<ApiVersion>1.0.1</ApiVers ion>
<CreationTime>2014-07-18T1 1:30:17</C reationTim e>
<SenderId>ABCD</SenderId>
<SenderAuth>18a51609-6ae2- 4ea7-b5bd- bc8806fd</ SenderAuth >
<ReceiverId>DEF</ReceiverI d>
<MessageType>STOCK_ADJUSTM ENT</Messa geType>
</Header>
<Body>
<MessageId>20140718113017_ </MessageI d>
<StockAdjustment>
<ProductNr>60000000006902< /ProductNr >
<Quantity>6</Quantity>
<StockTypeTo>NEW</StockTyp eTo>
<Reason>510</Reason>
</StockAdjustment>
</Body>
</Message>
</StockAdjustmentMsg>
</soapenv:Body>
</soapenv:Envelope>
Thanks
Pradeep
The output of the XSLT is below:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<StockAdjustmentMsg xmlns="http://www.abc-def.com/ns/schema">
<Message xmlns="">
<Header xmlns="http://www.abc-def.com/ns/schema">
<ApiVersion>1.0.1</ApiVersion>
<CreationTime>2014-07-18T11:30:17</CreationTime>
<SenderId>ABCD</SenderId>
<SenderAuth>18a51609-6ae2-4ea7-b5bd-bc8806fd</SenderAuth>
<ReceiverId>DEF</ReceiverId>
<MessageType>STOCK_ADJUSTMENT</MessageType>
</Header>
<Body xmlns="http://www.abc-def.com/ns/schema">
<MessageId>20140718113017_</MessageId>
<StockAdjustment>
<ProductNr>60000000006902</ProductNr>
<Quantity>6</Quantity>
<StockTypeTo>NEW</StockTypeTo>
<Reason>510</Reason>
</StockAdjustment>
</Body>
</Message>
</StockAdjustmentMsg>
</soapenv:Body>
</soapenv:Envelope>
<?xml version="1.0" encoding="UTF-8"?><soapenv<soapenv:Body>
<StockAdjustmentMsg xmlns="http://www.abc-def.com/ns/schema">
<Message xmlns="">
<Header xmlns="http://www.abc-def.com/ns/schema">
<ApiVersion>1.0.1</ApiVers
<CreationTime>2014-07-18T1
<SenderId>ABCD</SenderId>
<SenderAuth>18a51609-6ae2-
<ReceiverId>DEF</ReceiverI
<MessageType>STOCK_ADJUSTM
</Header>
<Body xmlns="http://www.abc-def.com/ns/schema">
<MessageId>20140718113017_
<StockAdjustment>
<ProductNr>60000000006902<
<Quantity>6</Quantity>
<StockTypeTo>NEW</StockTyp
<Reason>510</Reason>
</StockAdjustment>
</Body>
</Message>
</StockAdjustmentMsg>
</soapenv:Body>
</soapenv:Envelope>
It is adding namespace to Header and Body also. I only need Message to look like <Message xmlns="">. Below is how I need the output to look like:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<StockAdjustmentMsg xmlns="http://www.abc-def.com/ns/schema">
<Message xmlns="">
<Header>
<ApiVersion>1.0.1</ApiVersion>
<CreationTime>2014-07-18T11:30:17</CreationTime>
<SenderId>ABCD</SenderId>
<SenderAuth>18a51609-6ae2-4ea7-b5bd-bc8806fd</SenderAuth>
<ReceiverId>DEF</ReceiverId>
<MessageType>STOCK_ADJUSTMENT</MessageType>
</Header>
<Body>
<MessageId>20140718113017_</MessageId>
<StockAdjustment>
<ProductNr>60000000006902</ProductNr>
<Quantity>6</Quantity>
<StockTypeTo>NEW</StockTypeTo>
<Reason>510</Reason>
</StockAdjustment>
</Body>
</Message>
</StockAdjustmentMsg>
</soapenv:Body>
</soapenv:Envelope>
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<StockAdjustmentMsg xmlns="http://www.abc-def.com/ns/schema">
<Message xmlns="">
<Header>
<ApiVersion>1.0.1</ApiVers
<CreationTime>2014-07-18T1
<SenderId>ABCD</SenderId>
<SenderAuth>18a51609-6ae2-
<ReceiverId>DEF</ReceiverI
<MessageType>STOCK_ADJUSTM
</Header>
<Body>
<MessageId>20140718113017_
<StockAdjustment>
<ProductNr>60000000006902<
<Quantity>6</Quantity>
<StockTypeTo>NEW</StockTyp
<Reason>510</Reason>
</StockAdjustment>
</Body>
</Message>
</StockAdjustmentMsg>
</soapenv:Body>
</soapenv:Envelope>
Thanks
Pradeep
Actually you asked
<Message xmlns="">
which is mechanical to say that Message is NOT in the namespace of the higher up element it would inherit the default namespace from
(you are basically switching back to the null namespace for this element)
Now you ask to take out the entire Mesaage including children, to the null namespace
(note that you are making it different elements
the xmlns="" will not appear if the parent of Message is in the NULL namespace
Will post improved code in a minute
<Message xmlns="">
which is mechanical to say that Message is NOT in the namespace of the higher up element it would inherit the default namespace from
(you are basically switching back to the null namespace for this element)
Now you ask to take out the entire Mesaage including children, to the null namespace
(note that you are making it different elements
the xmlns="" will not appear if the parent of Message is in the NULL namespace
Will post improved code in a minute
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Geert,
Many thanks. Could you explain me the last two template match what they are doing?
Regards
Pradeep
Many thanks. Could you explain me the last two template match what they are doing?
Regards
Pradeep
The first one gets triggered on the Message element and creates a new one but only using the local name (essentialy removing the namespace) and continues processing in a mode. The second one picks up all elements in that mode and removes the namespace for all of them
Open in new window