Skip to Content
0
Former Member
Oct 08, 2009 at 05:42 AM

XSLT Mapping - replacing attribute value of a specific node

346 Views

Hi,

I want to replace the value of an attribute for a specific node. Can you please tell me how this can be achieved using XSLT coding?

The input file is as follows:

<?xml version="1.0" encoding="UTF-8"?>

http://www.govtalk.gov.uk/CM/envelope">

<EnvelopeVersion>2.0</EnvelopeVersion>

<Header>

<MessageDetails>

<Class>IR-PAYE-MOV</Class>

<Qualifier>request</Qualifier>

<Function>submit</Function>

<CorrelationID/>

<Transformation>XML</Transformation>

<GatewayTimestamp/>

</MessageDetails>

<SenderDetails>

<IDAuthentication>

<SenderID>isv142</SenderID>

<Authentication>

<Method>MD5</Method>

<Value>1L2xFE8WqHHI5iVMGhixAg==</Value>

</Authentication>

</IDAuthentication>

</SenderDetails>

</Header>

<GovTalkDetails>

<Keys>

<Key Type="TaxOfficeNumber">123</Key>

<Key Type="TaxOfficeReference">MD345</Key>

</Keys>

<ChannelRouting>

<Channel>

<URI>0142</URI>

</Channel>

</ChannelRouting>

</GovTalkDetails>

<Body>

http://www.govtalk.gov.uk/taxation/PAYE/MOV/09-10/1">

<IRheader>

<Keys>

<Key Type="TaxOfficeNumber">123</Key>

<Key Type="TaxOfficeReference">MD345</Key>

</Keys>

<PeriodEnd>2009-09-29</PeriodEnd>

<DefaultCurrency>GBP</DefaultCurrency>

<IRmark Type="generic">03Bfkipk6UDWSXLj77ObBVoK894=</IRmark>

<Sender>Company</Sender>

</IRheader>

<InYearMovements>

<EmployerName>form p60</EmployerName>

<P46 Statement="A">

<Name>

<Fore>Smith</Fore>

<Sur>John</Sur>

</Name>

<Address>

<Line>Sterling Residency</Line>

<Line>Gehde</Line>

<Line>Hedge End</Line>

<Line>Southampton</Line>

<PostCode>12345678</PostCode>

</Address>

<WorksNumber>20090030</WorksNumber>

<NINO>NP258719D</NINO>

<BirthDate>1985-07-11</BirthDate>

<Gender>male</Gender>

<StartDate>2009-04-20</StartDate>

<TaxCodeInUse>647L</TaxCodeInUse>

</P46>

</InYearMovements>

</IRenvelope>

</Body>

</GovTalkMessage>

I want to replace the value 'http://www.govtalk.gov.uk/taxation/PAYE/MOV/09-10/1' of attribute xmlns belonging to the node 'IRenvelope' with the value 'http://www.govtalk.gov.uk/taxation/PAYE/MOV/10-11/1'

So the output of the mapping should be:

<?xml version="1.0" encoding="UTF-8"?>

http://www.govtalk.gov.uk/CM/envelope">

<EnvelopeVersion>2.0</EnvelopeVersion>

<Header>

<MessageDetails>

<Class>IR-PAYE-MOV</Class>

<Qualifier>request</Qualifier>

<Function>submit</Function>

<CorrelationID/>

<Transformation>XML</Transformation>

<GatewayTimestamp/>

</MessageDetails>

<SenderDetails>

<IDAuthentication>

<SenderID>isv142</SenderID>

<Authentication>

<Method>MD5</Method>

<Value>1L2xFE8WqHHI5iVMGhixAg==</Value>

</Authentication>

</IDAuthentication>

</SenderDetails>

</Header>

<GovTalkDetails>

<Keys>

<Key Type="TaxOfficeNumber">123</Key>

<Key Type="TaxOfficeReference">MD345</Key>

</Keys>

<ChannelRouting>

<Channel>

<URI>0142</URI>

</Channel>

</ChannelRouting>

</GovTalkDetails>

<Body>

http://www.govtalk.gov.uk/taxation/PAYE/MOV/10-11/1">

<IRheader>

<Keys>

<Key Type="TaxOfficeNumber">123</Key>

<Key Type="TaxOfficeReference">MD345</Key>

</Keys>

<PeriodEnd>2009-09-29</PeriodEnd>

<DefaultCurrency>GBP</DefaultCurrency>

<IRmark Type="generic">03Bfkipk6UDWSXLj77ObBVoK894=</IRmark>

<Sender>Company</Sender>

</IRheader>

<InYearMovements>

<EmployerName>form p60</EmployerName>

<P46 Statement="A">

<Name>

<Fore>Smith</Fore>

<Sur>John</Sur>

</Name>

<Address>

<Line>Sterling Residency</Line>

<Line>Gehde</Line>

<Line>Hedge End</Line>

<Line>Southampton</Line>

<PostCode>12345678</PostCode>

</Address>

<WorksNumber>20090030</WorksNumber>

<NINO>NP258719D</NINO>

<BirthDate>1985-07-11</BirthDate>

<Gender>male</Gender>

<StartDate>2009-04-20</StartDate>

<TaxCodeInUse>647L</TaxCodeInUse>

</P46>

</InYearMovements>

</IRenvelope>

</Body>

</GovTalkMessage>

Thanks & Regards,

Aditi Naik