I have xml data like this:
<Invoice >
<cac:AllowanceCharge>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:AllowanceChargeReason>ISK:y!#x!#w!#q!#t!#</cbs:AllowanceChargeReason>
<cbc:MultiplierFactorNumeric>0.1</cbc:MultiplierFactorNumeric>
</Invoice>
I must split this AllowanceChargeReason by the !#
characters, and put the results in an array. and loop with this array as a result i want to get this result. How can i write xslt code for below result?
<table>
<xsl:for-each >
<tr>
.......
</tr>
</xsl>
</table>
Result:
</table>
<table>
<tr>
<td>
y
</td>
<td>
x
</td>
<td>
w
</td>
<td>
q
</td>
</tr>
</table>
To do this in XSLT 1.0, you would need to create a named template, which would call itself recursively. It would take as parameters a string to split, and the delimiter on which to split it
Note, in this case the 'select' values in the parameters are default values, and would only apply if no explicit parameter is passed to the template.
In the template, you would text if the text contains the delimiter
If so, you would output the first part of the string, using
substring-before
and then recursively call the named template usingsubstring-after
When the text doesn't contain the delimiter, just output it.
For example, given the following XML
And the following XSLT
Then the following is output
Do note you will have to take into account namespaces when you apply this to your actual XML sample.