'Convert XML to CSV (with node path as header) using XSLT

How can I convert the following XML to CSV using XSLT?

<tXML>
    <Header>
        <Source>XPTO</Source>
        <User_ID>127</User_ID>
        <Message_Type>Ship</Message_Type>
        <Company_ID>105</Company_ID>
        <Msg_Locale>English (United States)</Msg_Locale>
        <Version>2017</Version>
    </Header>
    <Message>
        <Ship>
            <ShipSummary>
                <ComName>XPTO 123</ComName>
                <FacName>6</FacName>
            </ShipSummary>
        </Ship>
    </Message>
</tXML>
tXML/Header/Source tXML/Header/User_ID tXML/Header/Message_Type tXML/Header/Company_ID tXML/Header/Msg_Locale tXML/Header/Version tXML/Message/Ship/ShipSummary/ComName tXML/Message/Ship/ShipSummary/FacName
XPTO 127 Ship 105 English (United States) 2017 XPTO 123 6

How can I get the "node path" for every value, and use that as the header?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source