Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts

    transform ID in XML file into string from relational

    We have an XML file that contains an element with an ID.
    <BANK_ID>5</BANK_ID>
    This ID gets sent from a 3rd party system and due to the 3rd party making changes recently, they have now added a 2nd XML file which has all the IDs and a 2nd code.
    <BANK_ID>5</BANK_ID>
    <BANK_CODE>AAA12345</BANK_CODE>

    These XML files are consumed by a downstream system.
    Is there a way to use an XLST to transform the Bank_ID in the first file and replace i with AAA12345 so we get:
    <BANK_ID>AAA12345</BANK_ID>

    We cannot so this in the downstream database due to coding difficulties and cost.

  • #2
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,304
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by qwertyjjj View Post
    Is there a way to use an XLST to transform the Bank_ID in the first file and replace i with AAA12345 so we get:
    <BANK_ID>AAA12345</BANK_ID>
    Yes:

    demo.xml
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="application/xml" href="demo.xslt"?>
    <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<title>Demo</title>
    		<style>
    			* { margin: 0; }
    			p, div { margin: 1rem; }
    			BANK_ID { font-weight: bolder; }
    		</style>
    	</head>
    	<body>
    		<p>This is paragraph A.</p>
    		<div>
    			<BANK_ID xmlns="">5</BANK_ID>
    			<BANK_CODE xmlns="">AAA12345</BANK_CODE>
    		</div>
    		<p>This is paragraph B.</p>
    	</body>
    </html>
    demo.xslt
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <t:transform xml:lang="en" xmlns:t="http://www.w3.org/1999/XSL/Transform" version="1.0">
    	<t:output method="xml" media-type="application/xhtml+xml" encoding="utf-8"/>
    	<t:template match="//BANK_ID">
    		<BANK_ID><t:value-of select="following-sibling::BANK_CODE"/></BANK_ID>
    	</t:template>
    	<t:template match="//BANK_CODE"/>
    	<t:template match="node() | @*">
    		<t:copy>
    			<t:apply-templates select="node() | @*"/>
    		</t:copy>
    	</t:template>
    </t:transform>
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •