Page 1 of 1

xslt: combine element attributes based on the value of another element's attribute

Posted: Thu Aug 12, 2021 9:09 am
by summer_seth
Is there a way to merge or combine row element based on the tables id and name?

Input:

<?xml version='1.0' encoding='UTF-8'?>
<ns1:Book xmlns:ns1="" id="3430">
<ns1:types>
<ns1:tables id="3431" name="001">
<ns1:table>
<ns1:row row1="A" />
<ns1:row row2="001" />
<ns1:row row3="111" />
</ns1:table>
</ns1:tables>
<ns1:tables id="3431" name="001">
<ns1:table>
<ns1:row row1="A" />
<ns1:row row2="002" />
<ns1:row row3="222" />
</ns1:table>
</ns1:tables>
<ns1:tables id="3435" name="002">
<ns1:table>
<ns1:row row1="A" />
<ns1:row row2="001" />
<ns1:row row3="111" />
<ns1:row row4="033793" />
<ns1:row row5="08122021" />
</ns1:table>
</ns1:tables>
</ns1:tabless>
</ns1:Book>


Aside from combining, have each row set in 1 line.

Output:

<?xml version='1.0' encoding='UTF-8'?>
<ns1:Book xmlns:ns1="" id="3430">
<ns1:types>
<ns1:tables id="3431" name="001">
<ns1:table>
<ns1:row row1="A" row2="001" row3="111" />
<ns1:row row1="A" row2="002" row3="222" />
</ns1:table>
</ns1:tables>
<ns1:tables id="3435" name="002">
<ns1:table>
<ns1:row row1="A" row2="001" row3="111" row4="033793" row5="08122021" />
</ns1:table>
</ns1:tables>
</ns1:tabless>
</ns1:Book>