cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT for payload with namespaces

Former Member
0 Kudos

Hello Experts, attn:Stefan.

I am using a XSLT to parse the input xml payload and retrieve the Value of a particular field which will be used for receiver determination.

The XSL code used by me is :


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<ns1:Receivers xmlns:ns1="http://sap.com/xi/XI/System">
<Receiver>
<Service>
<xsl:value-of select="NemRefusionIndberetningSamling/NemRefusionIndberetningStruktur/HeaderStruktur/ReferenceAttributTekst" />
</Service>
</Receiver>
</ns1:Receivers>
</xsl:template>
</xsl:stylesheet>

And the input payload I am getting is something like:



<?xml version="1.0" encoding="utf-8"?>
<NemRefusionIndberetningSamling >
	<DannetDatoTid>2010-04-22T12:14:28.036+02:00</DannetDatoTid>
	<NemRefusionIndberetningStruktur xmlns="urn:oio:abc:nemrefusionindberetning:2009.07.03" MessageID="1">
		<HeaderStruktur xmlns="urn:oio:abc:nemrefusionheader:2009.07.03">
			<FravaerTypeKode>Sygdom</FravaerTypeKode>
			<FravaerendeStruktur>
				<FravaerendeTypeKode>Loenmodtager</FravaerendeTypeKode>
				<LoenUnderFravaerIndikator>false</LoenUnderFravaerIndikator>
			</FravaerendeStruktur>
			<IndberetningUUIDIdentifikator>bf9cc44e-af15-4e19</IndberetningUUIDIdentifikator>
			<ReferenceAttributTekst>S70CLNT007</ReferenceAttributTekst>
		</HeaderStruktur>
......
.......
	</NemRefusionIndberetningStruktur>
</NemRefusionIndberetningSamling>

The XSLT works fine with above payload. But now we need to add namespaces in top level elements. So the payload will be like:


<NemRefusionIndberetningSamling xmlns="urn:oio:abc:nemrefusionsamling:2009.07.03" UUIDIdentifikator="DF8C1CB43B2E14F1A0C5005">

<DannetDatoTid>2010-04-22T12:14:28.036+02:00</DannetDatoTid>
	<NemRefusionIndberetningStruktur xmlns="urn:oio:abc:nemrefusionindberetning:2009.07.03" MessageID="1">
		<HeaderStruktur xmlns="urn:oio:abc:nemrefusionheader:2009.07.03">
			<FravaerTypeKode>Sygdom</FravaerTypeKode>
			<FravaerendeStruktur>
				<FravaerendeTypeKode>Loenmodtager</FravaerendeTypeKode>
				<LoenUnderFravaerIndikator>false</LoenUnderFravaerIndikator>
			</FravaerendeStruktur>
			<IndberetningUUIDIdentifikator>bf9cc44e-af15-4e19</IndberetningUUIDIdentifikator>
			<ReferenceAttributTekst>S70CLNT007</ReferenceAttributTekst>
		</HeaderStruktur>
......
.......
	</NemRefusionIndberetningStruktur>
</NemRefusionIndberetningSamling>

Top element being changed by addition of namespace, XSLT fails to retriev the value of required field i.e. <ReferenceAttributTekst>

Changed element:

"<NemRefusionIndberetningSamling xmlns="urn:oio:abc:nemrefusionsamling:2009.07.03" UUIDIdentifikator="DF8C1CB43B2E14F1A0C5005">"

I am sure that there should be a way to handle namespaces in XSLT. Please suggest me the correction to XSLT to handle this namespace addition to top element.

Kind Regards,

Abhijeet.

Accepted Solutions (1)

Accepted Solutions (1)

former_member181985
Active Contributor
0 Kudos

May I know why you are using XSLT mapping for such simple transformation for determining Dynamic Receivers....

Regards,

Praveen Gujjeti

Former Member
0 Kudos

Hi Praveen,

The input payload even though is XML is sent as a string. The structure will undergo frequent changes. Also the XML structure is very huge and complex, so the decission was taken to handle the input as a string to avoid changes to interface objects when structure changes.

The header part which has this field required for receiver determination will remain same even though rest of the structure undergoes some changes. So going for XSLT to handle the string xml payload.

Hope you can suggest some changes to xslt to handle namespaces.

Kind Regards,

Abhijeet.

stefan_grube
Active Contributor
0 Kudos

In XSLT you put a prefix before the XPATH rule like this:

p1:root/p2:subnode/element

you declare the namespaces in header as attribute xmlns:p1="..."

Something like:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:p1="..." ...>

In your example you have to consider, that namespaces without prefix are inherited to subnodes. That means you have to build your XPATH like this:

p1:NemRefusionIndberetningSamling/p2:NemRefusionIndberetningStruktur/p3:HeaderStruktur/p3:ReferenceAttributTekst

Former Member
0 Kudos

Hi Stefan,

I have followed the approach for using the prefix for namespaces. It works perfectly with namespaces now!

Thank you very much once again!

Kind Regards,

Abhijeet.

Points awarded!

Answers (0)