[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT1.0 distinct list of attributes across several

Subject: Re: XSLT1.0 distinct list of attributes across several nodes
From: "Peter Flynn peter@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 25 Jun 2018 22:46:04 -0000
Re:  XSLT1.0 distinct list of attributes across several
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 query:

$ lxprintf -e
'hopper[ancestor::post_press_version/post_press_version_id="25"][.!=""]'
"%s\n" @number test.xml | sort | uniq
1
2
3
5
$ lxprintf -e
'hopper[ancestor::post_press_version/post_press_version_id="26"][.!=""]'
"%s\n" @number test.xml | sort | uniq
1
2
3
6

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

  <xsl:output method="text"/>

  <xsl:key name="hoppers" match="hopper"
    use="concat(ancestor::post_press_version/
                post_press_version_id,'/',@number)"/>

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

  <xsl:template match="post_press_version">
    <xsl:variable name="vid" select="post_press_version_id"/>
    <xsl:value-of select="$vid"/>
    <xsl:for-each
      select="hopper_allocations/descendant::hopper
              [count(.|key('hoppers',concat($vid,'/',@number))[1])=1]">
      <xsl:sort select="@number"/>
      <xsl:if test="key('hoppers',concat($vid,'/',@number))[.!='']">
        <xsl:text>,</xsl:text>
        <xsl:value-of select="@number"/>
      </xsl:if>
    </xsl:for-each>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>

</xsl:stylesheet>


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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.