473,407 Members | 2,314 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,407 software developers and data experts.

Convert Question (From XML to XML) using XSLT?

Hi All,

I have following XML File:

<Header></Header>
<Category></Category>
<Item1></Item1>
<Item2></Item2>
<Category></Category>
<Item3></Item3>
Could someone please send me an example what is the XSLT text to
convert it to:

<Header>
<Category>
<Item1></Item1>
<Item2></Item2>
</Category>
<Category>
<Item3></Item3>
</Category>
</Header>

Thanks is advance,

Homer

May 29 '06 #1
3 1426
Homer wrote:
Hi All,

I have following XML File:

<Header></Header>
<Category></Category>
<Item1></Item1>
<Item2></Item2>
<Category></Category>
<Item3></Item3>
I hope you don't mean that. I hope you mean

<doc>
<Header></Header>
<Category></Category>
<Item></Item>
<Item></Item>
<Category></Category>
<Item></Item>
</doc>

(in other words, three occurrences of the Item element type, not one
each of three separately-named element types Item1, Item2, and Item3).

Could someone please send me an example what is the XSLT text to
convert it to:

<Header>
<Category>
<Item1></Item1>
<Item2></Item2>
</Category>
<Category>
<Item3></Item3>
</Category>
</Header>


<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="Category">
<Category>
<xsl:apply-templates
select="following-sibling::Item
[generate-id(preceding-sibling::Category[1]) =
generate-id(current())]" mode="included"/>
</Category>
</xsl:template>

<xsl:template match="Item"/>

<xsl:template match="Item" mode="included">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

///Peter
--
XML FAQ: http://xml.silmaril.ie/
May 29 '06 #2
Thanks so much Peter. It was a Big help.

May 30 '06 #3
This is a small problem. I am getting following result:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<Header/>
<Category>
<Item/>
<Item/>
</Category>
<Category>
<Item/>
</Category>
</root>

Instead of:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<Header>
<Category>
<Item></Item>
<Item></Item>
</Category>
<Category>
<Item></Item>
</Category>
</Header>
</root>

Do you know why?

May 30 '06 #4

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

Similar topics

1
by: Matt | last post by:
I want to use XML to store a document's configurations. And I can convert to different file format by using XSL. For example, convert to HTML, PDF, or RTF. But the contents are all stored in single...
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
2
by: chris | last post by:
Hi there, I create an XML file from a dataset like this: System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(FILENAME); dsUserData1.WriteXml(xmlSW, XmlWriteMode.WriteSchema);...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
7
by: Ish2000 | last post by:
Hello, I've a simple windows application and i want to be able to convert a csv file to xml. So far, i can browse for the csv file from the file structure and display in a textbox. I want to...
2
by: noopathan | last post by:
Hi experts , I have an excel file in the below format --------------------------------------------------------------------- CodeID CodeName Market Name Date...
1
by: luthriaajay | last post by:
I have an XML file in the format: <?xml version="1.0" encoding="UTF-8"?> <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4"><Order Acct="1" Px="480.25" SettlDt="2009-12-01" SettlTyp="0"...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
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
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,...
0
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...

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.