473,513 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting Values Based on Index

1 New Member
Hi there,

I have the following XML:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <parent> 
  3.     <metadata> 
  4.           <item name="column1" /> 
  5.           <item name="column2" /> 
  6.     </metadata> 
  7.     <data> 
  8.         <row> 
  9.             <value>10</value> 
  10.             <value>20</value> 
  11.         </row> 
  12.     </data> 
  13. </parent> 
and I need a way to output the following:

Expand|Select|Wrap|Line Numbers
  1. <parent>
  2.   <column1>10</column1>
  3.   <column2>20</column2>
  4. </parent>
I've gotten pretty close with the following XSLT:

Expand|Select|Wrap|Line Numbers
  1. <xsl:output method="xml" indent="yes"/>
  2. <xsl:strip-space elements="*"/>
  3.  
  4. <xsl:template match="parent/data/row">
  5.     <parent>
  6.         <xsl:apply-templates select="value" />
  7.     </parent>
  8. </xsl:template>
  9.  
  10. <xsl:template match="value">
  11.     <xsl:variable name="ename">
  12.         <xsl:value-of select="/parent/metadata/item[1]/@name" />
  13.      </xsl:variable>
  14.  
  15.     <xsl:element name="{$ename}">
  16.         <xsl:value-of select="."/>
  17.     </xsl:element>
  18. </xsl:template>
  19.  
  20. </xsl:stylesheet>
But the problem is that I don't know how to make the index of the selected <item> element equal to the value of position() of the <value> element being processed.

Any help would be greatly appreciated.

Thanks!
Dec 24 '10 #1
0 991

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2401
by: PW | last post by:
I use a multi-select menu in an ASP so the user can pick several values. <select multiple name="lbErrorType" size="12"> However, after I have saved the records to the DB, and the user comes...
0
2442
by: Qiang Han | last post by:
Hi, Folks, I am really frustrated by a bug of function-based index. Is there anyone has any idea on this? Please drop some line, thanks first. DETAILS: I have a table called Point_tab. I...
0
1164
by: Avinash Dhoot | last post by:
Hi, I have a 5 row table with the following values. key value 1 5 2 10 3 15 4 15 5 5
18
5674
by: booner | last post by:
I have a form that when it loads I would like to highlight the values (from a DB) that have been selected in a multiple selection list (<select multiple="true">. function onLoad() {...
4
4981
by: Rizyak | last post by:
This message is cross posted in alt.comp.lang.php & comp.lang.javascript I have a form for a user to input an establishment's hours and what time an event is taking place. After the user inputs...
5
7289
by: uthuras | last post by:
Machine : AIX 5.2 Product : UDB DB2 Release 8.1 FP4a I have problem loading data into destination table. The data file is huge with more than 6 Million records. This what i have done 1....
3
5554
by: John Dolan | last post by:
Hi all, I need some help here. I have an ActiveX object that requires me to pass in an array that is 1-based (as opposed to the normal 0-based index). Unfortunately the author of the ActiveX...
4
1810
by: J | last post by:
I am editing a pre-existing view. This view is already bringing data from 40+ tables so I am to modify it without screwing with anything else that is already in there. I need to (left) join it...
4
3610
by: Eugene Anthony | last post by:
I have a table that has a DateTime column which uses a DataTime datatype. How do I retrieve a range of records based on the month and year using ms sql? Eugene Anthony *** Sent via...
7
2048
by: LSGKelly | last post by:
I am working on a query that I would like to get the top 4 values based on a group. Here is the SQL: SELECT qRenPercRept1.CountOfccName, qRenPercRept1.Merged, qRenPercRept1.ccName,...
0
7384
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
7539
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...
1
7101
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
5686
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
5089
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
4746
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
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
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 ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.