473,372 Members | 928 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,372 software developers and data experts.

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="2006-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>2006-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:stylesheet 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()='creationNumber'">
<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>2006-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 Destinationdocument above.

Can anybody give me an XSLT-hint?

Thanks

May 29 '06 #1
2 2334


jkflens wrote:

The XML-source-document:

<?xml version="1.0" encoding="UTF-8"?>
<data creationTime="2006-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>2006-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:stylesheet
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
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...
3
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...
0
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...
2
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...
3
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...
5
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,...
4
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...
7
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...
0
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...
2
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.