Reputation: 3
I have the following input xml . I need to do couple of steps to get the desired out put. I am not well versed in XSLT. I can do basic templates. I am stuck on the following task
I need to change <WorkCompPolicyQuoteInqRq>
to <WorkCompPolicyQuoteInqRs>
. The issue here is the name of the tag may vary it could be <XXXYRq> <AbCRq>
But the position stays the same (the second child of InsuranceSvcRq
) and the last two characters are always "Rq".
I am not sure how to do this. I would appreciate any guidance. Thanks!
Input XML
<DATA>
<SignonRq>
</SignonRq>
<InsuranceSvcRq>
<RqUID>6D76AF16-56C0-4108-BD82-83985EDD6888</RqUID>
<WorkCompPolicyQuoteInqRq>
<RqUID>8CB1B8A1-83B2-4D94-8A9A-D5E801DD2E32</RqUID>
<TransactionRequestDt>2012-12-26T12:14:18</TransactionRequestDt>
<TransactionEffectiveDt>2012-10-01</TransactionEffectiveDt>
<CurCd>USD</CurCd>
</WorkCompPolicyQuoteInqRq>
</InsuranceSvcRq>
</DATA>
Desired Output
<DATA>
<Status>
<StatusCd>0</StatusCd>
<StatusDesc>ACORD Success</StatusDesc>
</Status>
<InsuranceSvcRs>
<RqUID>6D76AF16-56C0-4108-BD82-83985EDD6888</RqUID>
<WorkCompPolicyQuoteInqRs>
<RqUID>8CB1B8A1-83B2-4D94-8A9A-D5E801DD2E32</RqUID>
<TransactionRequestDt>2012-12-26T12:14:18</TransactionRequestDt>
<TransactionEffectiveDt>2012-10-01</TransactionEffectiveDt>
<CurCd>USD</CurCd>
<MsgStatus>
<MsgStatusCd>Error</MsgStatusCd>
<MsgErrorCd>DataError</MsgErrorCd>
<MsgStatusDesc>Request Failed</MsgStatusDesc>
<ExtendedStatus>
<ExtendedStatusCd>DataInvalid</ExtendedStatusCd>
<ExtendedStatusDesc>Message</ExtendedStatusDesc>
</ExtendedStatus>
</MsgStatus>
</WorkCompPolicyQuoteInqRs>
</InsuranceSvcRs>
</DATA>
Upvotes: 0
Views: 1004
Reputation: 22617
The position criterion (the said element always the second child of InsuranceSvRq
) is actually sufficient to identify this element. So, you do not have to also check if the last characters of the name are "Rq".
Write a template that matches a child of InsuranceSvcRq
if it is in the second position:
<xsl:template match="InsuranceSvcRq/*[position() = 2]">
Then, introduce a new element whose name is the concatenation of almost the whole original name (without any potential namespace prefix) save for the last character - and "s" at the end.
<xsl:element name="{concat(substring(local-name(),1,string-length() -1),'s')}">
Then, apply templates to the remainder of the document or do other things:
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
You might want to do something very similar with the InsuranceSvcRq
element itself.
The rest of the changes from your input XML to the output are trivial. Since you clearly state:
I can do basic templates.
I will leave them to you.
Upvotes: 2