XSLT: Normalize the spaces of incoming xml values

This xslt can remove the tailing whitespaces in xml.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="*">
    <xsl:copy>
      <xsl:for-each select="@*">
        <xsl:attribute name="{name()}">
          <xsl:value-of select="normalize-space()"/>
        </xsl:attribute>
      </xsl:for-each>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="text()">
    <xsl:value-of select="normalize-space()"/>
  </xsl:template>

</xsl:stylesheet>

Comments

  1. This is a very helpful XSLT! I was struggling with trailing whitespaces in XML files, and this solution worked perfectly. Thanks for sharing!"
    franchise Expo
    Franchise India Expo Delhi

    ReplyDelete
  2. Simple and effective approach to removing whitespaces. This is a must-have for anyone working with XML data."
    Silo Top Dust Filter in delhi
    vibro sifter delhi

    ReplyDelete
  3. reat post! It’s always nice to see small but impactful XSLT tricks like this. It works like a charm for cleaning up data."
    heavy duty rack manufacturer delhi
    Multi tier rack manufacturer delhi

    ReplyDelete
  4. This XSLT is a lifesaver when dealing with messy XML files. Thanks for posting such a useful solution!"
    slotted Angle rack manufacturer delhii
    pallet rack in delhi

    ReplyDelete
  5. This is a perfect way to handle extra spaces in XML files. It really streamlines the process and keeps the data clean."
    Dust collector manufacturer
    Franchise Opportunities

    ReplyDelete

Post a Comment

Popular posts from this blog

OSB actions in proxy service

Difference between Route, Service Callout, Publish

XQuery functions that supported by OSB