473,397 Members | 2,099 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,397 software developers and data experts.

How to convert attributes to element

Hello all,

Can't figure it out. :( Assume that we have 2 XML document:

Document1 (source):

<elements>
<elementA attribute1="value1" attribute2="value2" ... />
<elementA attribute1="value1" attribute2="value2" ... />
...
</elements>

Document2 (element description):

<elements>
<element name="elementA">
<attributes>
<attribute name="attribute1" description="Attribute1 desc" />
<attribute name="attribute2" description="Attribute2 desc" />
</attributes>
</element>
</elements>

Result document must have the following structure:

<elements>
<element name="elementA">
<attributes>
<attribute name="attribute1" description="Attribute1 desc"
value="value1" />
<attribute name="attribute2" description="Attribute2 desc"
value="value2" />
</attributes>
</element>
<element name="elementA">
<attributes>
<attribute name="attribute1" description="Attribute1 desc"
value="value1" />
<attribute name="attribute2" description="Attribute2 desc"
value="value2" />
</attributes>
</element>
</elements>

Please somebody help me,
Tod

Nov 12 '05 #1
1 4081
You want to use XSLT
(http://www.zvon.org/xxl/XSLTutorial/.../contents.html) which, if
you don't already know it, will take you a while to learn.

Then, to combine two XML documents into one, you have to choose one as
the primary document (probably your Document1), and use the other
document as a kind of reference lookup. You can do this using the XSLT
document() function, something like this:

<xsl:variable name="elementName" select="name()" />
<xsl:for-each select="@*">
<xsl:variable name="attributeName" select="name()" />
<xsl:variable name="attributeDescription"
select="document(Document2.xml)/elements/element[@name=$elementName]/attribute[@name=$attributeName]/@description"
/>
.... write output XML here...
</xsl:for-each>

A *HUGE* caveat: this is _not_ working XSLT code. I have not tested it.
It is just an idea of where to start. You cannot just plug it into an
XSLT document without understanding XSLT, and trust that the transform
will work. It won't. In particular, I've never tried XPath expressions
with double [] selection in them, so I don't even know if that works or
if I have the syntax right. The point is that there's a way, if you
understand XSLT, to monkey around with this and get it to work.

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
9
by: Soren Kuula | last post by:
Hi, I just can't find namespaces of attributes stated clearly enough in the XML namespace spec. But .. I hear rumors that attributes, unless qualified otherwise, default to the namespace of the...
7
by: Info 3000 | last post by:
Hello, I'm beginner in XML. I have just a little question : I understand that I can write : <Book> <Title> A nice day </Title> <Author> James Nicepen </Author> </Book>
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
6
by: Developer | last post by:
Hello, I'm experimenting with and XmlTextReader sample, and don't understand how the attributes are being processed. Here's the input: <xsd:element name="AA" type="BB"...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
6
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def>...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
7
by: samelzoro | last post by:
here is a problem in recursion: unexpected result ? by this program I just want to convert xml dom's document object to xml-string. (for all browsers) //load a xml function...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.