Strip text from XML elements, rearrange it, and concatenate it with XSLT?

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

 

4 comments on “Strip text from XML elements, rearrange it, and concatenate it with XSLT?”

  1. Gravatar of omega replica  omega replica
    Posted Monday, December 3, 2012 at 11:42:56 PM

    n XML how do I strip text from XML elements, or reaarrange it and concatenate it using XSLT

  2. Gravatar of hermes replica  hermes replica
    Posted Monday, March 18, 2013 at 5:23:14 AM

    There are numerous local retailers which market Hermes shopping bags with regard to a reduced amount of. Nonetheless, about to catch truly convinced which retailers are showing the truth.

  3. Gravatar of replica watches  replica watches
    Posted Tuesday, July 2, 2013 at 2:56:58 AM

    This is why on the web duplicate wrist watches industry gives you unique models with imitation wrist watches.

  4. Gravatar of benz can filter  benz can filter
    Posted Thursday, October 10, 2013 at 4:08:57 AM

    Situated on a stand-alone plot at 3rd Mile, Jalan Ipoh, Amcorp Auto's 3S centre fully complies with Volkswagen's corporate identity with 5,000 sq ft of showroom floor and 8,000 sq ft of service area.

Post a comment