xslt merging question

R

rottyguy70

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
 
M

Martin Honnen

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>
 
R

rottyguy70

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.
 
R

rottyguy70

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.
 
M

Martin Honnen

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top