xsl-list
[Top] [All Lists]

Re: [xsl] Find the number of elements that are prior to the seriesof elements that match a string?

2019-03-12 14:55:11
On 12.03.2019 20:21, Eliot Kimber ekimber(_at_)contrext(_dot_)com wrote:
I was thinking of doing something with looking up the individual byte() elements using key() on the string values but I couldn't think of an elegant way to split the input string into two-character chunks.

Interesting, why do you need the string splitting for the key? Wouldn't

  <xsl:param name="input" as="xs:string">04000000FF</xsl:param>
<xsl:variable name="len" as="xs:integer" select="string-length($input) idiv 2"/>

<xsl:key name="window" match="Bytes/Byte" use="string-join((., following-sibling::Byte[position() lt $len]))"/>

  <xsl:template match="/">
<xsl:value-of select="count(key('window', $input)[1]/preceding-sibling::Byte)"/>
  </xsl:template>

do?
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>