I am having a HECK of a time trying to get a list of unique values from a certain field in a group of pages. I have tried several different ways, but in effort to keep the code-pasting and -reading to a minimum, I'll just describe the two main techniques I'm trying.
I have a large group of pages of document type alias "SolutionItem". These pages have a data field I created on them called "Responsibility". Many of them share the same value, therefore when I try to create a dropdown to display them, I'd like only to show one of each. Like a SELECT DISTINCT Responsibility FROM ... in SQL. With me so far? Ok. So I tried this:
<xsl:for-each select="$currentPage/descendant-or-self::node/node [@nodeTypeAlias = 'SolutionItem' and contains(data[@alias = 'Industry'], $industry) and data [@alias = 'Responsibility'][not(.=following::data [@alias = 'Responsibility'])]]">
...and this gives me a very incomplete list. In other words, there are several SolutionItems which contain the given $industry whose Responsibility field value is never returned/written. I cannot figure out why. preceding::data [] yields the same result.
I am also trying:
<xsl:for-each select="$currentPage/descendant-or-self::node/node [@nodeTypeAlias = 'SolutionItem' and contains(data[@alias = 'Industry'], $industry) and data [@alias = 'Responsibility'][not(.=following::data [@alias = 'Responsibility'])]]">
And in this scenario I am getting many duplicates, even though when I write out the values of the current loop item value (<xsl:value-of select="data [@alias = 'Responsibility']"/>) and the folllowing item (<xsl:value-of select="following::data [@alias = 'Responsibility']"/>), I am indeed getting different values.
What am I doing wrong? I've spent HOURS on this problem and it just doesn't seem like something that should be that difficult.
getting a unique list of values from a data field
Hi,
I am having a HECK of a time trying to get a list of unique values from a certain field in a group of pages. I have tried several different ways, but in effort to keep the code-pasting and -reading to a minimum, I'll just describe the two main techniques I'm trying.
I have a large group of pages of document type alias "SolutionItem". These pages have a data field I created on them called "Responsibility". Many of them share the same value, therefore when I try to create a dropdown to display them, I'd like only to show one of each. Like a SELECT DISTINCT Responsibility FROM ... in SQL. With me so far? Ok. So I tried this:
...and this gives me a very incomplete list. In other words, there are several SolutionItems which contain the given $industry whose Responsibility field value is never returned/written. I cannot figure out why. preceding::data [] yields the same result.
I am also trying:
And in this scenario I am getting many duplicates, even though when I write out the values of the current loop item value (<xsl:value-of select="data [@alias = 'Responsibility']"/>) and the folllowing item (<xsl:value-of select="following::data [@alias = 'Responsibility']"/>), I am indeed getting different values.
What am I doing wrong? I've spent HOURS on this problem and it just doesn't seem like something that should be that difficult.
Any help would be VERY sincerely appreciated!
Thanks in advance,
Garrett
hi,
The xml file is <?xml version="1.0" encoding="utf-8"?>
<Nodes>
<Node>
<Id>1</Id>
</Node>
<Node>
<Id>2</Id>
</Node>
<Node>
<Id>3</Id>
</Node>
<Node>
<Id>1</Id>
</Node>
<Node>
<Id>2</Id>
</Node>
<Node>
<Id>3</Id>
</Node>
<Node>
<Id>4</Id>
</Node>
<Node>
<Id>3</Id>
</Node>
<Node>
<Id>5</Id>
</Node>
<Node>
<Id>6</Id>
</Node>
<Node>
<Id>6</Id>
</Node>
<Node>
<Id>7</Id>
</Node>
<Node>
<Id>8</Id>
</Node>
<Node>
<Id>7</Id>
</Node>
<Node>
<Id>8</Id>
</Node>
<Node>
<Id>9</Id>
</Node>
<Node>
<Id>9</Id>
</Node>
<Node>
<Id>10</Id>
</Node>
<Node>
<Id>10</Id>
</Node>
</Nodes>
The xsl is
<xsl:template match="/">
<xsl:variable name="unique-list" select="//Id[not(.=following::Id)]" />
<xsl:for-each select="$unique-list">
<xsl:value-of select="." />
</xsl:for-each>
</xsl:template>
I can get the distinct numbers. u can try in ur sample
is working on a reply...