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

Re: Handling position in non-atomic sequences

Subject: Re: Handling position in non-atomic sequences
From: "Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 2 May 2020 11:31:14 -0000
Re:  Handling position in non-atomic sequences
You can keep the variable as a sequence of elements and declare a function like this:

  <xsl:function name="my:index-of" as="xs:integer*">
    <xsl:param name="seq" as="node()*"/>
    <xsl:param name="nodes-in-question" as="node()*"/>
    <xsl:sequence select="index-of(
                            for $s in $seq
                              return generate-id($s),
                            for $n in $nodes-in-question
                              return generate-id($n)
                          )"/>
  </xsl:function>

If youbre using XSLT 3 you can use $seq ! generate-id() etc. for brevity.

Then my:index-of($headings, .) will give you the position of the context node within the sequence of headings.

Gerrit

On 02.05.2020 12:52, Michael MC<ller-Hillebrand mmh@xxxxxxxxx wrote:
Hi folks,

if a sequence stored in a variable consists of elements, we can not use the nice function index-of().

Also, if the variable is typed as="element()*" I cannot use the axes preceding-sibling or following-sibling. I can solve that by not typing the variable or use as="document-node()" after adding <xsl:document> to the variable's sequence constructor.

My current solution finding the position of the first <h1> in a sequence would be something like:

count($seq/h1[1]/preceding-sibling::*) + 1

with $seq being a sequence typed as document-node().

Are there better methods to get the position of a certain element in the sequence?

In my scenario I collect a certain set of elements using xsl:copy-of and want to process them in the context of that sequence (regarding position) and not in the context of their original document location.

Thanks a lot for any pointers,

- Michael

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.