Reputation: 1
I am looking out for an XSLT which can remove namespace prefix as well as empty tags , I have searched in forum I found two separate XSLT to achieve this, I am trying to find an XSLT which can do both.
Please note I am not very well verse in XSLT , so seeking help here.
source xml:
<ns1:DSBookingDetail xmlns:ns1="http://example.com">
<ns1:BookingNo>000123</ns1:BookingNo>
<ns1:SeqNo>1</ns1:SeqNo>
<ns1:LineType>Item</ns1:LineType>
<ns1:ProductCode>Box</ns1:ProductCode>
<ns1:ProductCategory></ns1:ProductCategory> <!-- empty tag -->
</ns1:DSBookingDetail>
target xml:(After name space prefix was removed and empty tags )
<DSBookingDetail>
<BookingNo>000123</BookingNo>
<SeqNo>1</SeqNo>
<LineType>Item</LineType>
<ProductCode>Box</ProductCode>
</DSBookingDetail>
Upvotes: 0
Views: 55
Reputation: 29052
You can reconstruct all elements by using their local-name()
as new name and check if their content is empty at the same time.
<xsl:template match="*[normalize-space(.)]"> <!-- only match non-empty elements -->
<xsl:element name="{local-name()}"> <!-- reconstruct element without namespace-prefix -->
<xsl:apply-templates select="node()|@*" /> <!-- recurse further -->
</xsl:element>
</xsl:template>
Upvotes: 1