cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT Mapping - replacing attribute value of a specific node

Former Member
0 Kudos

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"?>

<GovTalkMessage xmlns="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>

<IRenvelope xmlns="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"?>

<GovTalkMessage xmlns="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>

<IRenvelope xmlns="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

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member187339
Active Contributor
0 Kudos

Hi,

You get name of an attribute by this code

<xsl:for-each select="@*">

<xsl:text>Value of </xsl:text>

<xsl:value-of select="name(.)"/>

<xsl:text> is </xsl:text><xsl:value-of select="."/>

</xsl:for-each>

Change value by providing new value in <xsl:value-of select="."/>

Regards

suraj