I have an EDI text file which I need to modify using XSLT. I have first transformed the text file into xml which looks like below:
<data>ST^8^347</data>
<data>BAK^00^A^100001396^20240102^^^^20456^a</data>
<data>REF^OQ^5004506</data>
I just need to update the 8th position of the line starting with BAK which is 20456 in above code, to a new value say NEW. Position is determined by delimiter "^"
My xslt code looks like but not working
<data><xsl:value-of select="replace(.,(tokenize(.,'\\^')[9]),'NEW')"/></data>
Expected output is
<data>BAK^00^A^100001396^20240102^^^^NEW^a</data>
Cannot use substring because length of each positions can vary. I can use 8 time substring after but looking for a better approach if possible. Please help.
First you need to have a well-formed XML input:
XML
Then you can do:
XSLT 3.0
to get:
Result
Alternatively you could use:
Or: