could you support me with the following XSLT transformation:
Initial xml file:
<root>
<Invoice>
<ID>
<_>INV12345</_>
</ID>
<InvoiceTypeCode>
<_>01</_>
<listVersionID>1.0</listVersionID>
</InvoiceTypeCode>
<InvoicePeriod>
<StartDate>
<_>2017-11-26</_>
</StartDate>
<EndDate>
<_>2017-11-30</_>
</EndDate>
</InvoicePeriod>
<AccountingSupplierParty>
<AdditionalAccountID>
<_>id-1234</_>
<schemeAgencyName>name1</schemeAgencyName>
</AdditionalAccountID>
</AccountingSupplierParty>
</Invoice>
</root>
Final xml file:
<Invoice>
<ID>NV12345</ID>
<InvoiceTypeCode listVersionID="1.0">01</InvoiceTypeCode>
<InvoicePeriod>
<StartDate>2017-11-26</StartDate>
<EndDate>2017-11-30</EndDate>
</InvoicePeriod>
<AccountingSupplierParty schemeAgencyName="name1">
<AdditionalAccountID>id-1234</AdditionalAccountID>
</AccountingSupplierParty>
</Invoice>
It’s necessary to do:
- remove root tag;
- remove all tags <_>, but their values move to their parent tags;
- all others non <_> tags move as attributes to their parent tags.
Such task is happened while Jackson transformation of UBL (Universal Business Language) from JSON to XML.
I’ve just found how to remove the root tag:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- identity template -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<!-- remove root tag -->
<xsl:template match="/*">
<xsl:apply-templates select="node()" />
</xsl:template>
</xsl:stylesheet>
New contributor
Volodymyr Jacob Patriiuk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.