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

Re: Ordered union of sequences

Subject: Re: Ordered union of sequences
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Thu, 08 Apr 2010 18:07:45 +0200
Re:  Ordered union of sequences
On 08.04.2010 17:50, Michael M|ller-Hillebrand wrote:
Am 08.04.2010 um 16:09 schrieb Michael Kay:

It seems to me that you first want to create (or imagine) a graph: in your
example there are arcs k->o, o->p, p->c, a->b, b->c, etc.

Then you want to look for cycles in this graph. If any cycles exist, there
is no solution to your problem.

Thanks Michael, I guess I have to finally understand the graph stuff. I will turn to the example in the 4th edition p.251 ff. for a starter.

Am 08.04.2010 um 16:47 schrieb Imsieke, Gerrit, le-tex:

[... cool, ready-made example ...]

Does that make sense?

If I include<o/>  at the other position, i.e.,
I receive "Too many nested function calls. May be due to infinite recursion." as expected.

Gerrit, I am at early stages to understand the algorithm. The function counts the maximum number of preceding siblings on any available path and uses this as a sort key. This is some sort of creating a graph, backtracing to the beginning... which is what Michael suggested, isn't it.

Thanks a lot for the most valuable input!

I need a result and the inconsistency report, so the user can fix the input. I will be looking into stopping the infinite recursion somehow.

Here's a modified XSLT that will complain about <o/> if you include it inconsistently (<seq><k/><f/><z/><o/></seq>):

<?xml version="1.0" encoding="utf-8"?>
  version="2.0"  >


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

  <xsl:template match="foo">
      <xsl:for-each-group select="seq/*" group-by="name(.)" >
        <xsl:sort select="my:sortkey(., ())"/>
        <xsl:element name="{current-grouping-key()}" />

<xsl:function name="my:sortkey" as="xs:integer">
<xsl:param name="input" as="element(*)" />
<xsl:param name="previously-seen" as="xs:string*" />
<xsl:if test="name($input) = $previously-seen">
<xsl:message terminate="yes">Element <xsl:value-of select="name($input)"/> doesn't seem to occur at an deterministic position.
<xsl:variable name="preceding-siblings" select="$input/../../seq/*[name() = name($input)]/preceding-sibling::*[1]" as="element(*)*" />
<xsl:variable name="seen" select="distinct-values(($previously-seen, name($input)))" />
<xsl:sequence select="(max(for $ps in $preceding-siblings return my:sortkey($ps, $seen)) + 1, 1)[1]"/>


No time to explain how it works now. Later!


Current Thread


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.
First Name
Last Name
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.