numbering across elements

Discussion in 'XML' started by Mike Dickens, Oct 4, 2004.

  1. Mike Dickens

    Mike Dickens Guest

    hi,
    i have a query regarding numbering one set of elements as filtered by another set.
    eg if i have

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <a>
    <b i="1" j="aaaa"/>
    <b i="2" j="bbbb"/>
    <b i="3" j="aaaa"/>
    <c i="1" j="xxxx"/>
    <c i="2" j="yyyy"/>
    <c i="3" j="zzzz"/>
    </a>

    and i want a numbered c/@j with the same @i as a, where a/@j = "aaaa", ie i get

    <x>
    <y i="1" j="xxxx"/>
    <y i="2" j="zzzz"/>
    </x>

    (note the @i sequence is 1,2 not 1,3)

    what would the xslt look like to do this?

    thanks,
    mike.
    Mike Dickens, Oct 4, 2004
    #1
    1. Advertising

  2. Mike Dickens

    Marrow Guest

    Hi,

    Try something like...

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="xml" indent="yes"/>

    <xsl:key name="kLookupB" match="b[@j='aaaa']" use="@i"/>

    <xsl:template match="a">
    <x>
    <xsl:for-each select="c[key('kLookupB',@i)]">
    <y i="{position()}" j="{@j}"/>
    </xsl:for-each>
    </x>
    </xsl:template>
    </xsl:stylesheet>


    HTH
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator


    "Mike Dickens" <> wrote in message
    news:...
    > hi,
    > i have a query regarding numbering one set of elements as filtered by

    another set.
    > eg if i have
    >
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <a>
    > <b i="1" j="aaaa"/>
    > <b i="2" j="bbbb"/>
    > <b i="3" j="aaaa"/>
    > <c i="1" j="xxxx"/>
    > <c i="2" j="yyyy"/>
    > <c i="3" j="zzzz"/>
    > </a>
    >
    > and i want a numbered c/@j with the same @i as a, where a/@j = "aaaa", ie

    i get
    >
    > <x>
    > <y i="1" j="xxxx"/>
    > <y i="2" j="zzzz"/>
    > </x>
    >
    > (note the @i sequence is 1,2 not 1,3)
    >
    > what would the xslt look like to do this?
    >
    > thanks,
    > mike.
    Marrow, Oct 4, 2004
    #2
    1. Advertising

  3. Mike Dickens

    Mike Dickens Guest

    ah yes, this makes sense now.

    thanks for the help,
    mike.

    "Marrow" <> wrote in message news:<shf8d.126$>...
    > Hi,
    >
    > Try something like...
    >
    > <?xml version="1.0"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="xml" indent="yes"/>
    >
    > <xsl:key name="kLookupB" match="b[@j='aaaa']" use="@i"/>
    >
    > <xsl:template match="a">
    > <x>
    > <xsl:for-each select="c[key('kLookupB',@i)]">
    > <y i="{position()}" j="{@j}"/>
    > </xsl:for-each>
    > </x>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    >
    > HTH
    > Marrow
    > http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    > http://www.topxml.com/Xselerator
    >
    >
    > "Mike Dickens" <> wrote in message
    > news:...
    > > hi,
    > > i have a query regarding numbering one set of elements as filtered by

    > another set.
    > > eg if i have
    > >
    > > <?xml version="1.0" encoding="ISO-8859-1"?>
    > > <a>
    > > <b i="1" j="aaaa"/>
    > > <b i="2" j="bbbb"/>
    > > <b i="3" j="aaaa"/>
    > > <c i="1" j="xxxx"/>
    > > <c i="2" j="yyyy"/>
    > > <c i="3" j="zzzz"/>
    > > </a>
    > >
    > > and i want a numbered c/@j with the same @i as a, where a/@j = "aaaa", ie

    > i get
    > >
    > > <x>
    > > <y i="1" j="xxxx"/>
    > > <y i="2" j="zzzz"/>
    > > </x>
    > >
    > > (note the @i sequence is 1,2 not 1,3)
    > >
    > > what would the xslt look like to do this?
    > >
    > > thanks,
    > > mike.
    Mike Dickens, Oct 5, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. buran

    numbering rows in datagrid

    buran, Jul 7, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    463
    Saravana
    Jul 7, 2003
  2. buran

    numbering rows in datagrid

    buran, Oct 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    514
    Cowboy \(Gregory A. Beamer\)
    Oct 15, 2003
  3. =?Utf-8?B?Q2hyaXM=?=

    form field auto numbering with unique value

    =?Utf-8?B?Q2hyaXM=?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    434
    John Saunders
    Jan 1, 2005
  4. Andy Fish
    Replies:
    2
    Views:
    448
    Andy Fish
    Apr 5, 2005
  5. Mike Dickens

    numbering across different elements

    Mike Dickens, Oct 27, 2004, in forum: XML
    Replies:
    10
    Views:
    614
    William Park
    Nov 3, 2004
Loading...

Share This Page