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

Re: Find the number of elements that are prior to the

Subject: Re: Find the number of elements that are prior to the seriesof elements that match a string?
From: "Eliot Kimber ekimber@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 12 Mar 2019 19:20:49 -0000
Re:  Find the number of elements that are prior to the
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. But I'm sure there's
a clever XPath 3 way to do it that I'm just not seeing. Easy to do with a
recursive function or xsl:iterator or analyze-string but I suspect there's a
more succinct way to do it.

So what is the easiest/clearest/most-clever way in XPath 3 to break a string
of arbitrary length into a sequence of strings of a fixed size?

Cheers,

E.
--
Eliot Kimber
http://contrext.com


o;?On 3/12/19, 2:02 PM, "Costello, Roger L. costello@xxxxxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

    Michael Kay wrote:

    > let $candidates := index-of(/Bytes/Byte, substring($req, 1, 2)) return
$candidates[string-
    > join(subsequence(/Bytes/Byte, ., $len), '') eq $req][1] - 1

    Wow!

    That is mind-blowing!

    Thank you Michael!

    /Roger


    > On 12 Mar 2019, at 17:35, Costello, Roger L. costello@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
    >
    > Hi Folks,
    >
    > I have an XML document containing a long list of Byte elements, e.g.,
    >
    > <Bytes>
    >    <Byte hexAddress="0">4D</Byte>
    >    <Byte hexAddress="1">5A</Byte>
    >    <Byte hexAddress="2">90</Byte>
    >    <Byte hexAddress="3">00</Byte>
    >    <Byte hexAddress="4">03</Byte>
    >    <Byte hexAddress="5">00</Byte>
    >    <Byte hexAddress="6">00</Byte>
    >    <Byte hexAddress="7">00</Byte>
    >    <Byte hexAddress="8">04</Byte>
    >    <Byte hexAddress="9">00</Byte>
    >    <Byte hexAddress="A">00</Byte>
    >    <Byte hexAddress="B">00</Byte>
    >    <Byte hexAddress="C">FF</Byte>
    >    <Byte hexAddress="D">FF</Byte>
    >    ...
    > </Bytes>
    >
    > I have a string of hex values, e.g.,
    >
    > 04000000FF
    >
    > You can see that the string is contained within this series of Byte
elements:
    >
    >    <Byte hexAddress="8">04</Byte>
    >    <Byte hexAddress="9">00</Byte>
    >    <Byte hexAddress="A">00</Byte>
    >    <Byte hexAddress="B">00</Byte>
    >    <Byte hexAddress="C">FF</Byte>
    >
    > I want to find the number of <Byte> elements that occur prior to the
series of Byte elements.
    >
    > I figured one approach is to convert all the Byte text node values into
a string and then perform string manipulations:
    >
    > string-length(substring-before(string-join(/Bytes/Byte/text(), ''),
    > '04000000FF')) idiv 2
    >
    > Note: I divided by two because each Byte has 2 digits.
    >
    > That seems to work, but I suspect it is horribly inefficient because it
creates a string containing all the Byte text node values and there may be
tens or hundreds of thousands of Byte elements.
    >
    > What is an efficient way to solve this problem?
    >
    > /Roger

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.