xslt merging question

Discussion in 'XML' started by rottyguy70@yahoo.com, Nov 1, 2005.

  1. Guest

    hello, am trying to do the following with little success. any help is
    appreciated.

    1) assume i have a static mapping:

    a -> 1
    b -> 2
    c -> 3

    2) i need to read through some data, let's say set [g, i, j] and create
    a new (joined/merged) mapping:

    a -> 1
    b -> 2
    c -> 3
    g -> 4
    i -> 5
    j -> 6

    3) with this new mapping, i need to x-ref it against another set.
    assume this 3rd set is [ a, a, g, i, c ] my resultant set should be [
    {a->1}, {a->1}, {g->4}, {i->5}, {c->3} ].

    i understand how to do 1 & 3 but not sure of how i can do 2. is there
    a way to merge or create a new mapping/node-set based on 2 (or more)
    maps/sets?

    thanks
     
    , Nov 1, 2005
    #1
    1. Advertising

  2. wrote:


    > 1) assume i have a static mapping:
    >
    > a -> 1
    > b -> 2
    > c -> 3
    >
    > 2) i need to read through some data, let's say set [g, i, j] and create
    > a new (joined/merged) mapping:
    >
    > a -> 1
    > b -> 2
    > c -> 3
    > g -> 4
    > i -> 5
    > j -> 6


    > i understand how to do 1 & 3 but not sure of how i can do 2. is there
    > a way to merge or create a new mapping/node-set based on 2 (or more)
    > maps/sets?


    If you are looking for an XSLT solution it would ease our task to
    understand what you are looking for if you presented XML markup as the
    possible input and output and not some other notation.
    XSLT 1.0 has the function named document to load additional XML
    documents and process them so merging is certainly possible:
    <http://www.w3.org/TR/xslt#document>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 1, 2005
    #2
    1. Advertising

  3. Guest

    hey mike, sorry for the confusion. assume i have the following:

    1) static xml
    <items>
    <item id="1" type="clothes"/>
    <item id="2" type="cars"/>
    <item id="3" type="tvs"/>
    </items>

    ** this should be easy

    2) i need to derive a unique set from the following:
    <new-items>
    <new-item type="house"/>
    <new-item type="boats"/>
    </new-items>

    <new-items>
    <new-item type="windows"/>
    <new-item type="boats"/>
    </new-items>

    ** i can use muenchian to get uniques

    2b) i need to combine (1) with (2) to get:
    <items>
    <item id="1" type="clothes"/>
    <item id="2" type="cars"/>
    <item id="3" type="tvs"/>
    <item id="4" type="house"/>
    <item id="5" type="boats"/>
    <item id="6" type="windows"/>
    </items>

    *** i'm unsure how to do this and in particular concat the 2 maps and
    gen the sequential id's for house, boats, and windows.

    3) finally, for some set of items
    <items2>
    <item2 type="house"/>
    <item2 type="boats"/>
    <items2>

    i need to x-ref it to my 2b list and produce:

    <items2>
    <item2 type="house" id="4"/>
    <item2 type="boats" id="5"/>
    </items2>

    hope that's more clear.

    thanks.
     
    , Nov 1, 2005
    #3
  4. Guest

    hey martin (i typed mike in the last response), sorry for the
    confusion. assume i have the following:

    1) static xml
    <items>
    <item id="1" type="clothes"/>
    <item id="2" type="cars"/>
    <item id="3" type="tvs"/>
    </items>

    ** this should be easy

    2) i need to derive a unique set from the following:
    <new-items>
    <new-item type="house"/>
    <new-item type="boats"/>
    </new-items>

    <new-items>
    <new-item type="windows"/>
    <new-item type="boats"/>
    </new-items>

    ** i can use muenchian to get uniques

    2b) i need to combine (1) with (2) to get:
    <items>
    <item id="1" type="clothes"/>
    <item id="2" type="cars"/>
    <item id="3" type="tvs"/>
    <item id="4" type="house"/>
    <item id="5" type="boats"/>
    <item id="6" type="windows"/>
    </items>

    *** i'm unsure how to do this and in particular concat the 2 maps and
    gen the sequential id's for house, boats, and windows.

    3) finally, for some set of items
    <items2>
    <item2 type="house"/>
    <item2 type="boats"/>
    <items2>

    i need to x-ref it to my 2b list and produce:

    <items2>
    <item2 type="house" id="4"/>
    <item2 type="boats" id="5"/>
    </items2>

    hope that's more clear.

    thanks.
     
    , Nov 1, 2005
    #4
  5. wrote:


    > 1) static xml
    > <items>
    > <item id="1" type="clothes"/>
    > <item id="2" type="cars"/>
    > <item id="3" type="tvs"/>
    > </items>


    > 2) i need to derive a unique set from the following:
    > <new-items>
    > <new-item type="house"/>
    > <new-item type="boats"/>
    > </new-items>
    >
    > <new-items>
    > <new-item type="windows"/>
    > <new-item type="boats"/>
    > </new-items>
    >
    > ** i can use muenchian to get uniques


    If those are two different documents then I think grouping with key is
    difficult as I think a key applies always to nodes in one particular
    document but not across documents. You might need an extra step that
    first combines those two documents.

    > 2b) i need to combine (1) with (2) to get:
    > <items>
    > <item id="1" type="clothes"/>
    > <item id="2" type="cars"/>
    > <item id="3" type="tvs"/>
    > <item id="4" type="house"/>
    > <item id="5" type="boats"/>
    > <item id="6" type="windows"/>
    > </items>


    Well you can certainly do

    <xsl:variable name="itemCount" select="count(items/item)" />

    and

    <xsl:template match="items">
    <xsl:copy>
    <xsl:apply-templates select="@*" />
    <xsl:apply-templates select="item" />
    <xsl:variable name="new-items"
    select="document('test2005110102.xml', /)/new-items/new-item" />
    <xsl:apply-templates select="$new-items[not(@type =
    preceding-sibling::new-item/@type)]" />
    </xsl:copy>
    </xsl:template>

    and

    <xsl:template match="new-item">
    <item id="{$itemCount + position()}" type="{@type}" />
    </xsl:template>



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 1, 2005
    #5
    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. Yannick Patois

    Merging two XML tree: xslt or dom ?

    Yannick Patois, Jul 20, 2004, in forum: XML
    Replies:
    1
    Views:
    957
    Uche Ogbuji
    Jul 23, 2004
  2. Replies:
    18
    Views:
    2,816
    Joseph Kesselman
    Oct 4, 2006
  3. Replies:
    0
    Views:
    532
  4. JMan
    Replies:
    7
    Views:
    486
    Martin Honnen
    Oct 15, 2008
  5. Andrew McFarland

    Merging tables with XSLT

    Andrew McFarland, May 29, 2009, in forum: XML
    Replies:
    1
    Views:
    2,565
    Andrew McFarland
    May 29, 2009
Loading...

Share This Page