By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,585 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

xslt merging question

P: n/a
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 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


ro********@yahoo.com 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/
Nov 1 '05 #2

P: n/a
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 '05 #3

P: n/a
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 '05 #4

P: n/a


ro********@yahoo.com 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/
Nov 1 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.