In XML how do I strip text from XML elements, or reaarrange it
and concatenate it using XSLT
Considering the following XML:
<root>
<contrib contrib-type="author">
<name>
<last-name>Simpson</last-name>
<first-name>Bart</first-name>
</name>
</contrib>
<contrib contrib-type="author">
<name>
<last-name>Zoidberg</last-name>
<first-name>Dr.</first-name>
</name>
</contrib>
</root>
How can I transform the contents of these elements to get this
output in an XML format using XSLT?
<Authors contrib-type="author">Bart Simpson</Authors>
<Authors contrib-type="author">Dr. Zoidberg</Authors>
Solution would be for above like that
using XSLT with efficient way
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<!-- identity rule -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- Authors -->
<xsl:template match="contrib[@contrib-type='author']">
<Authors contrib-type="{@contrib-type}">
<xsl:value-of select = "concat(name/first-name, ' ', name/last-name)" />
</Authors>
</xsl:template>
</xsl:stylesheet>
I hope this would help you guys,
Thank you for going through this article