473,790 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file

Hello,

i convert one XML-document by using XSLT into another XML-document.
First change all attributes to elements is no problem.
Then i try to insert a new element into the new document by XSLT,
but it doesn't work correctly :-(
Example:
The XML-source-document:

<?xml version="1.0" encoding="UTF-8"?>
<data creationTime="2 006-05-31" creationNumber= "1">
<set number="0001" info="test"/>
<set number="0002" info="test"/>
</data>
The following XML-destination-document has to become
(watch the new element "sets"):

<?xml version="1.0" encoding="UTF-8"?>
<data>
<creationTime>2 006-05-31</creationTime>
<creationNumber >1</creationNumber>
<sets>
<set>
<number>0001</number>
<info>test</info>
</set>
<set>
<number>0002</number>
<info>test</info>
</set>
</sets>
</data>
Here is my XSLT-stylesheet-attempt:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*">
<xsl:element name="{name()}" >
<xsl:value-of select="."/>
</xsl:element>
<xsl:if test="name()='c reationNumber'" >
<sets/>
</xsl:if>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="*|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here is the result with wrong positioned "sets":

<?xml version="1.0" encoding="UTF-8"?>
<data>
<creationTime>2 006-05-31</creationTime>
<creationNumber >1</creationNumber>
<sets/>
<set>
<number>0001</number>
<info>test</info>
</set>
<set>
<number>0002</number>
<info>test</info>
</set>
</data>

The element "sets" should not to be positioned simply before the first
set-Element,
it should be positiond around the set-Elements, thus as shown in the
XML Destinationdocu ment above.

Can anybody give me an XSLT-hint?

Thanks

May 29 '06 #1
2 2371


jkflens wrote:

The XML-source-document:

<?xml version="1.0" encoding="UTF-8"?>
<data creationTime="2 006-05-31" creationNumber= "1">
<set number="0001" info="test"/>
<set number="0002" info="test"/>
</data>
The following XML-destination-document has to become
(watch the new element "sets"):

<?xml version="1.0" encoding="UTF-8"?>
<data>
<creationTime>2 006-05-31</creationTime>
<creationNumber >1</creationNumber>
<sets>
<set>
<number>0001</number>
<info>test</info>
</set>
<set>
<number>0002</number>
<info>test</info>
</set>
</sets>
</data>


You need to write a template for data then that inserts the sets
elements as the parent for set elements:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="data">
<xsl:copy>
<xsl:apply-templates select="@*" />
<sets>
<xsl:apply-templates />
</sets>
</xsl:copy>
</xsl:template>

<xsl:template match="@*">
<xsl:element name="{name()}" ><xsl:value-of select="." /></xsl:element>
</xsl:template>

<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
--

Martin Honnen
http://JavaScript.FAQTs.com/
May 29 '06 #2
This is a top-XSLT-hint,

now it works correctly

THANKS for your hint martin

May 30 '06 #3

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

Similar topics

2
5649
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their first name, last name, email, etc. The data are then sent to a PHP script (reg.php). The data are then inserted into a table (reg) in MS SQL server. I have declared the variables like this: if (!(isset($_POST))) { $FirstName = "" ;
3
4521
by: jain-neeraj | last post by:
Hi, We have a problem in our mobile calls billing software. To solve it, I need an outer join in a complicated query. Following are the simplified tables with sample data: create table CONTROL1 (CTRL_NO number(2)); insert into CONTROL1 values (10); create table CONTROL2 (CTRL_NO number(2));
0
1335
by: Dean A. Hoover | last post by:
I am doing a contract job for a client with some existing messy data. I am trying to find a solution to a problem of many-to-many mappings between two tables in a database. See below for my contrived example. Tables a and b each have simple primary keys. They also have 2 columns that are related to each other. In other words, a1 and b1 carry the same "key" type of data. Same thing with a2 and
2
2886
by: Gunnar Vøyenli | last post by:
Hi Some days ago I posted a problem with a query. Thaks to Dave and John, I got a little closer to a solution. Their suggestion was a solution to my problem as I stated it, but the real problem is a bit more complicated, so I have to expand the original problem a bit. The query has to handle unknown number of departments, and a date interval. I want: 1) For each day, for each department: a list of (from at_work table) all
3
6115
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection Timed out) I am using the Data Access Application Blocks as ASP.NET (using VB.NET) and SQL 2000. In there first question there can be up to 27 answers. So I figured instead of making 27 different trips to the database I woulc just concatenate my...
5
5463
by: Ritesh | last post by:
Hi All, According to my observation using SP_WHO2 in my database, some INSERT statements are getting blocked by SELECT statements. Though the blocking SELECT statement is having ReadPast hint, i think, it will only read past locked resources but will not guarantee the select statement itself not blocking other statements(in my case Insert). According to my knowledge
4
2747
by: Bradley Burton | last post by:
I'm using Allen Brown's code for audit logging (http://allenbrowne.com/AppAudit.html), but I'm having a problem. My aud table doesn't populate with the tracking info at all. I think it might be a problem with the table set-up. I just can't find the problem. These are the fields in my table: Table1 ID (primary key) AutoNumber
7
4353
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the sqldatasource of the formview. If i put this textboxes outside the table everything works well, but as soon as i put them inside the table (in order to organize the layout in the right way) they doesn't work. They works only as eval() and not bind()...
0
1104
by: ZoeNet | last post by:
Hi all, The table structures are below. The table category_cat is built on the adjacency model (where the parent and child entries are both stored in the same table). For my problem, I've created 3 tables for example. The category_cat table containts drill-downs of pets (from animal type to animal color). I have the table product_pdt that containts "I hate shirts" of every animal category. And the table pdttocat_ptc joins the other 2...
2
3097
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography section: Discography --------------------- DiscID
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10413
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.