Re: [xsl] XSLT1.0 distinct list of attributes across several nodes

Subject: Re: [xsl] XSLT1.0 distinct list of attributes across several nodes
From: "Mark Anderson mark.anderson@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 26 Jun 2018 21:00:24 -0000
Thanks for reply Peter, unfortunately I can't use anything other than XSL
(with MSXML), as it's a 3rd party app that invokes the transform. All we can
do is provide our own XSL

By distinct attributes, I did, in fact, mean the distinct values of the number
attribute. Apologies of that

a Segerdahl company
Mark Anderson
Director of ERP Systems
Phone: 847-419-3329
Mobile: 13125764332
Email: mark.anderson@xxxxxxxxx
-----Original Message-----
From: Peter Flynn peter@xxxxxxxxxxx
Sent: Monday, June 25, 2018 5:46 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] XSLT1.0 distinct list of attributes across several nodes

On 25/06/18 19:52, Mark Anderson mark.anderson@xxxxxxxxx wrote:
> I'm restricted to XSLT1.0 with no extensions.

Are you allowed to use other computer utilities?

> I need to get a list of distinct attributes across a set of nodes.

I think there is a terminological problem here, because I'm not clear what you
mean by "distinct attributes".

> From the simplified XML below, the result should be 1,2,3,5 for the
> first post_press_version (25) and 1,2,3,6 for the second (26)

By deduction, what I *think* you mean is "the number attribute of hopper
elements which have content in either sequence". The simple answer is a direct

$ lxprintf -e
"%s\n" @number test.xml | sort | uniq
$ lxprintf -e
"%s\n" @number test.xml | sort | uniq

The lxprintf utility uses XPath 1.0; the above solution relies on the standard
(UNIX and GNU/Linux) sort and uniq utilities which may not be acceptable if
you are required to implement the solution *entirely* within an XSLT 1.0
script. If that is the case, then you were very close to an answer:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="";

  <xsl:output method="text"/>

  <xsl:key name="hoppers" match="hopper"

  <xsl:template match="/">
    <xsl:apply-templates select="order/post_press_version"/>

  <xsl:template match="post_press_version">
    <xsl:variable name="vid" select="post_press_version_id"/>
    <xsl:value-of select="$vid"/>
      <xsl:sort select="@number"/>
      <xsl:if test="key('hoppers',concat($vid,'/',@number))[.!='']">
        <xsl:value-of select="@number"/>


Peter Flynn | Principal Consultant | Silmaril Consultants | Cork p.p*
Ireland | b +353 86 824 5333 | b	 peter@xxxxxxxxxxx | p

[demime 1.01d removed an attachment of type image/jpeg which had a name of image689031.jpg]

Current Thread