Re: [xsl] Ordered union of sequences

Subject: Re: [xsl] Ordered union of sequences
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Thu, 08 Apr 2010 18:22:20 +0200
Still found the time to correct a typo and to remove the redundant distinct-values():

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



On 08.04.2010 18:07, Imsieke, Gerrit, le-tex wrote:
<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:message>
</xsl:if>
<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]"/>
</xsl:function>

Current Thread