473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

xslt merging question

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
4 1466


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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Dingley | last post by:
I've just started on a new project and inherited a huge pile of XSLT (and I use the term "pile" advisedly !) It runs at glacial speed, and I need to fix this this. Platform is MSXML 4 / ASP ...
1
by: Yannick Patois | last post by:
Hi, I would like to merge two XML document, or more exacly enrich a document by inheritiong from another. I read a bit about XSLT and I know a bit of python/sax/dom, and I dont know where I...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
2
by: Dave Taylor | last post by:
Is there a decent explanation of how menu merging with MDI forms work in VB.NET? I've read through the online help and it still seems that whenever I change menus around or whatever, it breaks...
2
by: Stefan | last post by:
Hi there! I'm very new to XML and XSLT, so while working i encountered the following, probably very easy to solve, problem. i've got 2 XML-files, which look like this: LinesOfCode.xml:...
0
by: david.paik | last post by:
Given the data: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="C:\junk\830new.xslt"?> <SC830> <SC830_3 bano="S67777" cuno="002620" year="2007" week="38"...
2
by: astroboiii | last post by:
New to the whole xml thing and finding w3schools to be an excellent resource. Now down to my question: I have several xml files I need to parse through and grab relevant information from and...
12
by: blackirish | last post by:
Hi all, I am trying to merge 2 XML files that first of all i need to compare nodes of both files according to 2 attributes in the nodes. If those 3 attributes are equal, i need to replace the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.