Advertisement
rplantiko

XSLT transformation to strip unnecessary whitespace

Jun 16th, 2016
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 0.62 KB | None | 0 0
  1. <!-- Removes whitespace between element tags (done with <xsl:strip-space>)
  2.     AND normalizes all text nodes
  3.     (i.e. deletes leading and trailing spaces, and comprises \s+ to single spaces) -->
  4. <xsl:stylesheet version="1.0"
  5. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  6.     <xsl:output method="xml" omit-xml-declaration="yes"/>
  7.     <xsl:strip-space elements="*"/>  
  8.   <xsl:template match="@*|node()">
  9.     <xsl:copy>
  10.       <xsl:apply-templates select="@*|node()"/>
  11.     </xsl:copy>
  12.   </xsl:template>
  13.   <xsl:template match="text()">
  14.     <xsl:value-of select="normalize-space(.)"/>
  15.   </xsl:template>
  16. </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement