Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt merging question

Reply
Thread Tools

xslt merging question

 
 
rottyguy70@yahoo.com
Guest
Posts: n/a
 
      11-01-2005
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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-01-2005


http://www.velocityreviews.com/forums/(E-Mail Removed) 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/
 
Reply With Quote
 
 
 
 
rottyguy70@yahoo.com
Guest
Posts: n/a
 
      11-01-2005
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.

 
Reply With Quote
 
rottyguy70@yahoo.com
Guest
Posts: n/a
 
      11-01-2005
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.

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      11-01-2005


(E-Mail Removed) 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merging tables with XSLT Andrew McFarland XML 1 05-29-2009 03:27 PM
merging two sequences in xslt JMan XML 7 10-15-2008 04:47 PM
XSLT question: How to lookup another tag's children in XSLT yinglcs@gmail.com XML 18 10-03-2006 11:22 PM
XSLT sorting / merging / summing david.paik@huscointl.com XML 0 09-20-2006 02:12 PM
Merging two XML tree: xslt or dom ? Yannick Patois XML 1 07-23-2004 07:17 PM



Advertisments