vincentdj
vincentdj

Reputation: 265

creating array of integers of a given length in xsl

I have to create an array of integers of length $lung. The elements of the array vary from 1 to $limit in ascending order. That is, the first element must have value 1, the second value 2 up to $limit, after which it starts again from value 1 to $limit. This is a draft of my code:

<xsl:variable name="limit" select="count(documen('./db/list.xml')/root_list/list"/> 
<xsl:variable name="lung" select="(6) div (./lunghezza)"/>
<xsl:variable name="array" as="xs:integer">
    <Item>1</Item>
    <Item>2</Item>
      ... 
    <Item>$limit</Item>
    <Item>1</Item>
      ...
    <Item>$limit</Item>
</xsl:variable>

how to load the array? I am a beginner. thank you very much.

Upvotes: 0

Views: 1109

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167696

Well XSLT does not have arrays. With XSLT 1.0 you have node sets, with 2.0 you have sequences (of nodes or atomic values). So with XSLT 2.0 you can create a sequence of integer values with 1 to $limit e.g. <xsl:variable name="array" select="1 to $limit, 1 to $limit"/> creates a sequence of 2 * $limit values.

[edit] Perhaps

<xsl:variable name="array" select="(for $n in 1 to (xs:integer(ceiling($lung div $limit))) return (1 to $limit))[position() le $lung]"/>

is what you want, it creates a sequence of integer values of length $lung which contains subsequences ranging from 1 to $limit where the last subsequence is cut off to ensure the length is exactly $lung.

Upvotes: 1

Related Questions