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

Grouping by element

Is there any way in XSLT to achive below XML in required output

Want to transform element on same level with different element name.

XML:-

Expand|Select|Wrap|Line Numbers
  1. <Root>
  2. <Parent>
  3. <Make>Make</Make>
  4. <Para>Line 1 $100.00</Para>
  5. <Para>Line 1 $200.00</Para>
  6. <Para>Line 1 $300.00</Para>
  7. <Make>Make</Make>
  8. <Para>Line 1 $500.00</Para>
  9. <Para>Line 1 $600.00</Para>
  10. </Parent>
  11. </Root>
Required Output:-
Expand|Select|Wrap|Line Numbers
  1. <Root>
  2. <Parent>
  3. <Make>Make</Make>
  4. <Para_1>Line 1 $100.00</Para_1>
  5. <Para_2>Line 1 $200.00</Para_2>
  6. <Para_1>Line 1 $300.00</Para_1>
  7. <Make>Make</Make>
  8. <Para_1>Line 1 $500.00</Para_1>
  9. <Para_2>Line 1 $600.00</Para_2>
  10. </Parent>
  11. </Root>
Jul 28 '10 #1
3 1451
Dormilich
8,658 Expert Mod 8TB
if you have the logic, when to attach _1 and _2, this should be possible. I’d use <xsl:element> for that.
Jul 28 '10 #2
Logic is i want make group of <para> and increment them with variable in my sample i group them by 2 in group it appends _1 to first and _2 to second para.
Jul 28 '10 #3
jkmyoung
2,057 Expert 2GB
What's the logic for the 3rd group?
Do you just alternate 1 and 2?
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="Para">
  2.   <xsl:variable name="name">
  3.     <xsl:text>Para_</xsl:text>
  4.     <xsl:choose>
  5.       <xsl:when test="position() mod 2 = 1">1</xsl:when>
  6.       <xsl:otherwise>2</xsl:otherwise>
  7.     </xsl:choose>
  8.   </xsl:variable>
  9.   <xsl:element name="{$name}">
  10.     <xsl:value-of select="."/>
  11.   </xsl:element>
  12. </xsl:template>
Jul 29 '10 #4

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

Similar topics

3
by: Kevin Brown | last post by:
Is there anyway to generate this type of resulting HTML table from this XML using XSLT? Basically I need to be able to consult 2 trees of data to generate the HTML, but I have not been able to...
5
by: Mike King | last post by:
I don't know how to group the following data in the way I want it. I want the output of the transformation to be "5678". Does anyone know what I am doing worry? <?xml version="1.0"?> <data>...
2
by: Tristan Miller | last post by:
Greetings. I have a question involving sorting and grouping output using XSLT. I am trying to produce a publication list from a BibTeX-like XML file: <bibxml:file...
7
by: Eivind | last post by:
Hi, I'm creating XML-files from printed documents. According to the DTD I have to use, there has to be pagebreaks in the XML-file. These pagebrakes must be located whenever a new page in the...
2
by: Chris Beach | last post by:
Hi there. I'd like to be able to group together inputs on an HTML form inside, say, a <div> or <fieldset> and then use javascript to iterate through the controls in the group and disable them....
7
by: Zhang Weiwu | last post by:
Hello. This is problem puzzled me a long time. I wish to organize some block elements and let them flow one after each other like text. Think about a album, I wish the album have 12 thumbnails,...
0
by: JemPower | last post by:
I wonder if anyone has some advice or suggestions on a problem I have. I've populated a datagrid and have a radiobutton in the first column which is for the users to select a row. The problem is...
6
by: jkoufala | last post by:
Hi I am new to XSLT and i have a problem with grouping. What im trying to do is group using two elements as a unique identifier. This is output from another program which outputs the same element...
1
by: Sandeep Singh | last post by:
Hi, How to do group by in XSLT ? I tried on the following codes: <files> <file name="swablr.eps" size="4313" project="mars"/> <file name="batboy.wks" size="424" ...
0
by: Leira | last post by:
Hi, I have a problem with grouping. My source XML has <record> elements that have a @name and a @group attribute. It looks something like this: <root> <result> <record name="test1"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
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
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
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,...

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.