View Single Post
Old August 22nd, 2019, 06:07 AM
Martin Honnen Martin Honnen is offline
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts

It seems like grouping by name and then checking if there is at least one non-empty element in the group is a way to establish the columns you want to output:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""

  <xsl:output method="html" indent="yes" html-version="5"/>

  <xsl:template match="/">
        <title>.NET XSLT Fiddle Example</title>
  <xsl:template match="custom-data/columns">
      <xsl:variable name="columns" select="columns"/>
      <xsl:variable name="non-empty-cols"
          <xsl:for-each-group select="$columns/*" group-by="name(.)">
      <table border="1">
                  <xsl:for-each select="$non-empty-cols">
                          <xsl:value-of select="."/>
              <xsl:apply-templates select="columns">
                  <xsl:with-param name="cols" select="$non-empty-cols"/>
  <xsl:template match="columns/columns">
      <xsl:param name="cols"/>
          <xsl:apply-templates select="*[name() = $cols]"/>

  <xsl:template match="columns/columns/*">
          <xsl:value-of select="."/>

Online sample at
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog

Last edited by Martin Honnen; August 22nd, 2019 at 06:09 AM.. Reason: adding link to sample
The Following User Says Thank You to Martin Honnen For This Useful Post: (August 23rd, 2019)