First,I don't have good enough experience on xslt. I have received xml file from thirdparty and some of field lengths are not acceptable in our system. I would like to split the string and make well xml format before read the xml file from our system. I know it can be done with xslt but I do not have enough xslt knowledge.
In this example, we assume "Doc_Header_Comments" and "Doc_Line_Comments" max length is 6 characters only accept in our system.
Here is sample input and except format after transform with xslt.
Input xml format
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Inbound_Sales_Document xmlns="urn:xmlports/x50000">
<Doc_Sender_Id />
<Doc_Date_Format>yyyyMMdd</Doc_Date_Format>
<Doc_Time_Format>hhmmss</Doc_Time_Format>
<Doc_Header>
<General>
<Doc_Header_Doc_Type>Order</Doc_Header_Doc_Type>
<Doc_Header_Doc_No>202011231836178441</Doc_Header_Doc_No>
<Doc_Header_Order_Date>20200023</Doc_Header_Order_Date>
<Doc_Header_Comments>ABCDEFGHIJKLMNOP</Doc_Header_Comments>
</General>
</Doc_Header>
<Doc_Line>
<Doc_Line_Order_No>202011231836178441</Doc_Line_Order_No>
<Doc_Line_Order_Line_No>1</Doc_Line_Order_Line_No>
<Doc_Line_Comments>ABCDEFGHIJKLMNOP</Doc_Line_Comments>
</Doc_Line>
<Doc_Line>
<Doc_Line_Order_No>202011231836178441</Doc_Line_Order_No>
<Doc_Line_Order_Line_No>1</Doc_Line_Order_Line_No>
<Doc_Line_Comments>ABC</Doc_Line_Comments>
</Doc_Line>
</Inbound_Sales_Document>
Output xml format after transform with xslt
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Inbound_Sales_Document xmlns="urn:xmlports/x50000">
<Doc_Sender_Id />
<Doc_Date_Format>yyyyMMdd</Doc_Date_Format>
<Doc_Time_Format>hhmmss</Doc_Time_Format>
<Doc_Header>
<General>
<Doc_Header_Doc_Type>Order</Doc_Header_Doc_Type>
<Doc_Header_Doc_No>202011231836178441</Doc_Header_Doc_No>
<Doc_Header_Order_Date>20200023</Doc_Header_Order_Date>
<Doc_Header_Comments>
<Comments>ABCDE</Comments>
<Comments>FGHIJ</Comments>
<Comments>KLMNO</Comments>
<Comments>P</Comments>
</Doc_Header_Comments>
</General>
</Doc_Header>
<Doc_Line>
<Doc_Line_Order_No>202011231836178441</Doc_Line_Order_No>
<Doc_Line_Order_Line_No>1</Doc_Line_Order_Line_No>
<Doc_Line_Comments>
<Comments>ABCDE</Comments>
<Comments>FGHIJ</Comments>
<Comments>KLMNO</Comments>
<Comments>P</Comments>
</Doc_Line_Comments>
</Doc_Line>
<Doc_Line>
<Doc_Line_Order_No>202011231836178441</Doc_Line_Order_No>
<Doc_Line_Order_Line_No>1</Doc_Line_Order_Line_No>
<Doc_Line_Comments>
<Comments>ABC</Comments>
</Doc_Line_Comments>
</Doc_Line>
</Inbound_Sales_Document>
I found similar case at XSLT - split string on every nth character in loop but I have no idea how to make it as my requirement.
Could someone pls help here. Many thanks