473,387 Members | 1,864 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,387 software developers and data experts.

Create tag names via XSL

I have the following XML:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ORDERS>
<ORDER>
<ORDER_ID>123</ORDER_ID>
<X>a</X>
<X>e</X>
<X>f</X>
</ORDER>
<ORDER>
<ORDER_ID>124</ORDER_ID>
<X>a</X>
<X>b</X>
<X>c</X>
</ORDER>
</ORDERS>

Is it possible to create the following XML document via XSL?

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ORDERS>
<ORDER>
<ORDER_ID>123</ORDER_ID>
<X1>a</X1>
<X2>e</X2>
<X3>f</X3>
</ORDER>
<ORDER>
<ORDER_ID>124</ORDER_ID>
<X1>a</X1>
<X2>b</X2>
<X3>c</X3>
</ORDER>
</ORDERS>

Any ideas?

Thanx in advance,

Chris

Jul 20 '05 #1
4 1260
Additon: I know that there will bee a maximum of 32 x-entries in the
source document, the exact amount can vary, so there must be a
dynamically solution.

Chris

Jul 20 '05 #2
Chris wrote:
Is it possible to create the following XML document via XSL?


xsl:copy-of can do this for you:

<ORDERS>
<xsl:copy-of select="descendant::*" />
</ORDERS>

Or didn't you mean to get an exact copy of the document?
JW

Jul 20 '05 #3
Janwillem Borleffs wrote:
Or didn't you mean to get an exact copy of the document?


No, the X elements were changed to X1, X2, X3, etc.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Jul 20 '05 #4


Chris wrote:
I have the following XML:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ORDERS>
<ORDER>
<ORDER_ID>123</ORDER_ID>
<X>a</X>
<X>e</X>
<X>f</X>
</ORDER>
<ORDER>
<ORDER_ID>124</ORDER_ID>
<X>a</X>
<X>b</X>
<X>c</X>
</ORDER>
</ORDERS>

Is it possible to create the following XML document via XSL?

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ORDERS>
<ORDER>
<ORDER_ID>123</ORDER_ID>
<X1>a</X1>
<X2>e</X2>
<X3>f</X3>
</ORDER>
<ORDER>
<ORDER_ID>124</ORDER_ID>
<X1>a</X1>
<X2>b</X2>
<X3>c</X3>
</ORDER>
</ORDERS>


Yes, one way to do it is

<?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" encoding="ISO-8859-1" />

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

<xsl:template match="X">
<xsl:element name="X{count(preceding-sibling::X) + 1}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>

</xsl:stylesheet>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #5

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

Similar topics

7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
24
by: flkeyman | last post by:
Work in legal office. Trying to create solid designed database structure. This is list of tables w/fields and primary keys. Any comments/advice greatly appreciated. tbl-Defendants CaseNumber...
3
by: MLH | last post by:
I was running the following code while logged in as a user belonging only to the Users group. Set usrNew = .CreateUser(Me!UserID) 'The user ID is in a control on the form usrNew.PID =...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
1
by: clir | last post by:
Hi, I'm trying to create views on all my existing tables and for that I'd like to create a script or so. I don't want to specify the '*' for the columns in the create view statement. I prefer...
3
by: DKelley | last post by:
I'm receiving a "severe" error that I can't seem to trap and evaluate in SQL Server 2000 (and no, I can't switch to 2005, this is on our customers' machines). And I've not been able to find info on...
0
by: kurtf | last post by:
Hope somebody could help me with the creation of a table in sqlite3 from python. I am developing an application that allows a user to import a data file and insert the data into a sqlite3...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.