473,503 Members | 13,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL - to insert a node

Hi,
I have an xml :

<DataRecords>
<Point Alias='A' Value='1' Status='0' />
<Point Alias='B' Value='2' Status='0' />
</DataRecords>
I have needed by an XSL to insert a node between <DataRecords> and <Point>

Example :

<DataRecords>
<Record>
<Point Alias='A' Value='1' Status='0' />
</Record>
<Record>
<Point Alias='B' Value='2' Status='0' />
</Record>
</DataRecords>

Can anyone help me?

Thanks

Beni

Nov 12 '05 #1
2 4904


Beniamin Tecar wrote:

I have an xml :

<DataRecords>
<Point Alias='A' Value='1' Status='0' />
<Point Alias='B' Value='2' Status='0' />
</DataRecords>
I have needed by an XSL to insert a node between <DataRecords> and <Point>

Example :

<DataRecords>
<Record>
<Point Alias='A' Value='1' Status='0' />
</Record>
<Record>
<Point Alias='B' Value='2' Status='0' />
</Record>
</DataRecords>


Simply use the identity transformation and add one template for <Point>
elements that wraps them into a <Record> element:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" encoding="UTF-8" />

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

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

</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
"Beniamin Tecar" <be*******************@nivis.com> wrote in message news:<uK**************@TK2MSFTNGP15.phx.gbl>...
<DataRecords>
<Point Alias='A' Value='1' Status='0' />
<Point Alias='B' Value='2' Status='0' />
</DataRecords> <DataRecords>
<Record>
<Point Alias='A' Value='1' Status='0' />
</Record>
<Record>
<Point Alias='B' Value='2' Status='0' />
</Record>
</DataRecords>


<xsl:for-each select="DataRecords/Point">
<xsl:text disable-output-escaping="yes">&lt;Record&gt;</xsl:text>
<Point>
<xsl:attribute name="Alias"><xsl:value-of select="@Alias" /></xsl:attribute>
<xsl:attribute name="Value"><xsl:value-of select="@Value" /></xsl:attribute>
<xsl:attribute name="Status"><xsl:value-of select="@Status" /></xsl:attribute>
<xsl:text disable-output-escaping="yes">&lt;/Record&gt;</xsl:text>
</xsl:for-each>

_Randal
Nov 12 '05 #3

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

Similar topics

5
13810
by: Tony B | last post by:
Hi I need to insert a new node into an exisiting XML file using VBScript. The file has the following structure: <TRANSACTION> <ORDER> <BILLING>... </BILLING> <ORDER_TOTALS>... </ORDER_TOTALS>...
4
12386
by: mike | last post by:
Hello. Let's say I have the following XML document: <ROOT><Element1>Some Text</Element1></ROOT> I want to add a new element after Element1. I tried the following but, naturally, it doesn't...
10
5094
by: florian | last post by:
Hi, we have a contention problem because of an application which tries to insert a duplicate row in a table with primary key. This insert fails of course but the locks are not released within...
3
22064
by: Andrew Clark | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** it's been a while since i have poseted to this newsgroup, but for a long time i was not programming at all. but now that i am out of...
2
1340
by: Patrick | last post by:
Hi, im trying to first insert a node in the xml file and save it. XmlDocument mDoc = new XmlDocument(); mDoc.Load("struct.xml"); XmlNode singleNode; XmlNode newNode =...
2
3670
by: wombat53 | last post by:
Hi Group Are there any DB2 UDB ESE DPF V8.2 users exploiting "buffered inserts" (BIND parm INSERT BUF) *and* "multi-row INSERTS" (many rows associated with the VALUES clause of the INSERT to...
4
3882
by: mathon | last post by:
Hello, im currently implementing a binary search tree means, that a greater number than root will be added as right child and a less number as left child. My insert function looks currently like...
6
19981
by: askmatlab | last post by:
Hello all: I would like to insert a number into a linked list in ascending order. Is the following function correct? void insert(Node **node, int v) { Node *tmp = (Node...
7
1457
by: E.F | last post by:
Hi everybody, I get lost trying to insert a node in my xml file with readfile, xpath, xpathnavigator, etc... 1/ my xml file looks like that : <PUPILL_CP_1> <YEAR_2006> <OCTOBRE...
10
10476
by: Aditya | last post by:
Hi All, I would like to know how it is possible to insert a node in a linked list without using a temp_pointer. If the element is the first element then there is no problem but if it is in...
0
7212
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
7098
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
7364
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
7470
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
5604
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,...
1
5026
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...
0
4696
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...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1524
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 ...

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.