I need help with transforming XML file to text file. Firstly the assignment was transforming XML file to text file using xsl template. Now XML file has element ID1 that is a string with "," delimiter. I need to parse that string and create a row for each value parsed from that string. Other attributes should remain the same. Is it doable?
Input file:
<?xml version="1.0" encoding="UTF-8"?>
<LoadData>
<value>
<File1>
<Time>2020/05/26 09:24:22</Time>
<Documentcs>
<Documentc id="09004e21802fcc5e">
<ID1>ID_0002, ID_0001</ID1>
<ID2>myP_001</ID2>
<ID3>SOP</ID3>
<ID4>MAY-26-2020 09:18:11</ID4>
<ID5>30</ID5>
<ID6>Days</ID6>
<ID7>Event</ID7>
<ID8>JUN-25-2020 09:18:11</ID8>
<ID9>N</ID9>
<EOF>!##!</EOF>
</Documentc>
</Documentcs>
</File1>
</value>
</LoadData>
XSL template:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8" indent="no" />
<xsl:variable name="newLine">
<xsl:text> </xsl:text>
</xsl:variable>
<!--main template-->
<xsl:template match="/LoadData/value/CurriculumItemConnectorFeed">
<xsl:text>ID1 | ID2 | ID3 | ID4 | ID5 | ID6 | ID7 | ID8 | ID9 | !##!</xsl:text>
<xsl:value-of select="$newLine" />
<!-- <xsl:value-of select="Time" />
<xsl:value-of select="$newLine" />
<xsl:value-of select="count(Documents/Document)" />
<xsl:value-of select="$newLine" /> -->
<xsl:apply-templates select="Documentcs/Documentc" mode="feed" />
<!-- <xsl:text>!##!</xsl:text> -->
</xsl:template>
<!--document template-->
<xsl:template match="Documentcs/Documentc" mode="feed">
<xsl:for-each select="*">
<xsl:if test="position() > 1"><xsl:text>|</xsl:text>
</xsl:if>
<xsl:value-of select="translate(.,'|','_')" />
</xsl:for-each>
<xsl:value-of select="$newLine" />
</xsl:template>
</xsl:stylesheet>
Current output file:
ID1 | ID2 | ID3 | ID4 | ID5 | ID6 | ID7 | ID8 | ID9 | !##!
ID_0002, ID_0001|myP_001|SOP|MAY-26-2020 09:18:11|30|Days|Event|JUN-25-2020 09:18:11|N|!##!
Desired output file:
ID1 | ID2 | ID3 | ID4 | ID5 | ID6 | ID7 | ID8 | ID9 | !##!
CURR_ID_0001|myP_001|SOP|MAY-26-2020 09:18:11|30|Days|Event|JUN-25-2020 09:18:11|N|!##!
CURR_ID_0002|myP_001|SOP|MAY-26-2020 09:18:11|30|Days|Event|JUN-25-2020 09:18:11|N|!##!