p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   nonempty check for an element at the same level (http://p2p.wrox.com/showthread.php?t=100345)

msambasiva@gmail.com August 22nd, 2019 02:52 AM

nonempty check for an element at the same level


I am trying to find the element names and count which are nonempty at any level


<comments>Identifier of the aging bucket.</comments>
<comments>Who column: indicates the user who last updated the row.</comments>
<comments>Descriptive Flexfield: segment of the user descriptive flexfield.</comments>
<flexfield-mapping>Aging </flexfield-mapping>

I want to generate a table from the above data. The trick is, if there is no data for a column at any where, we need to exclude that column from the output table.

Ex: status,precision elements is empty for all the columns. SO we don't need to display status and precision column in output table.

How to get the number of elements without data at the same level and there names?



Martin Honnen August 22nd, 2019 06:07 AM

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="http://www.w3.org/1999/XSL/Transform"

  <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 https://xsltfiddle.liberty-development.net/pPzifqw

msambasiva@gmail.com August 23rd, 2019 02:27 AM

Its working! Thank you so much for quick response!!

All times are GMT -4. The time now is 08:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.