coalesce.xslt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. -->
  14. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  15. <xsl:output indent="yes"/>
  16. <xsl:template match="/">
  17. <xsl:apply-templates select="*">
  18. <xsl:with-param name="n" select="*"/>
  19. </xsl:apply-templates>
  20. </xsl:template>
  21. <xsl:template match="*">
  22. <xsl:param name="n"/>
  23. <xsl:variable name="name" select="name()"/>
  24. <xsl:variable name="s" select="$n[name()=$name]"/>
  25. <xsl:if test="count(.|$s[1])=1">
  26. <xsl:copy>
  27. <xsl:copy-of select="@*"/>
  28. <xsl:apply-templates select="$s/*">
  29. <xsl:with-param name="n" select="$s/*"/>
  30. </xsl:apply-templates>
  31. </xsl:copy>
  32. </xsl:if>
  33. </xsl:template>
  34. </xsl:stylesheet>