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

XSLT Transformation

Hi,

i am quite new to xml and need to transform an existing xml file:
<Location>
<ArticleDescription>
<Description>Shirt Hawaii</Description>
</ArticleDescription>
<ArticleMiscs>
<ArticleMisc>
<Country>DEU</Country>
<Size>32</Size>
</ArticleMisc>
<art:ArticleMisc>
<Country>USA</art:Country>
<Size>XS</art:Size>
</ArticleMisc>
<ArticleMisc>
<Country>GBR</art:Country>
<Size>6</art:Size>
</ArticleMisc>
</ArticleMiscs>
</Location>

this should be transformed to:

<Location>
<ArticleDescription>
<Description>Shirt Hawaii</Description>
</ArticleDescription>
<ArticleMiscs>
<ArticleMisc>
<Country>DEU</Country>
<Size>32</Size>
</ArticleMisc>
</ArticleMiscs>
</Location>

<Location>
<ArticleDescription>
<Description>Shirt Hawaii</Description>
</ArticleDescription>
<ArticleMiscs>
<ArticleMisc>
<Country>USA</art:Country>
<Size>XS</art:Size>
</ArticleMisc>
</ArticleMiscs>
</Location>

<Location>
<ArticleDescription>
<Description>Shirt Hawaii</Description>
</ArticleDescription>
<ArticleMiscs>
<ArticleMisc>
<Country>GBR</art:Country>
<Size>6</art:Size>
</ArticleMisc>
</ArticleMiscs>
</Location>

So the original file contains 3 "ArticleMisc" Sections per <Location>,
the tranformed one only one Misc per Location. Can anybody give me a
hint how this van be done via XSLT?

Thanks,

Jens
Jul 15 '08 #1
2 1297
Hi,

try this code

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Location">
<xsl:for-each select="//ArticleMisc">
<Location>
<xsl:copy-of select="../../ArticleDescription"/>
<ArticleMiscs>
<xsl:copy-of select="."/>
</ArticleMiscs>
</Location>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Regards,
Balaji. M
sql-ebooks.blogspot.com

On Jul 15, 11:56*am, Jens Hofmeier <aaaa111...@discardmail.comwrote:
Hi,

i am quite new to xml and need to transform an existing xml file:
<Location>
* * * * * <ArticleDescription>
* * * * * * <Description>Shirt Hawaii</Description>
* * * * * *</ArticleDescription>
* * * * <ArticleMiscs>
* * * * * <ArticleMisc>
* * * * * * <Country>DEU</Country>
* * * * * * <Size>32</Size>
* * * * * </ArticleMisc>
* * * * * <art:ArticleMisc>
* * * * * * <Country>USA</art:Country>
* * * * * * <Size>XS</art:Size>
* * * * * </ArticleMisc>
* * * * * <ArticleMisc>
* * * * * * <Country>GBR</art:Country>
* * * * * * <Size>6</art:Size>
* * * * * </ArticleMisc>
* * * * *</ArticleMiscs>
</Location>

this should be transformed to:

<Location>
* * * * * <ArticleDescription>
* * * * * * <Description>Shirt Hawaii</Description>
* * * * * *</ArticleDescription>
* * * * <ArticleMiscs>
* * * * * <ArticleMisc>
* * * * * * <Country>DEU</Country>
* * * * * * <Size>32</Size>
* * * * * </ArticleMisc>
* * * *</ArticleMiscs>
</Location>

<Location>
* * * * * *<ArticleDescription>
* * * * * * <Description>Shirt Hawaii</Description>
* * * * * *</ArticleDescription>
* * * * <ArticleMiscs>
* * * * * *<ArticleMisc>
* * * * * * <Country>USA</art:Country>
* * * * * * <Size>XS</art:Size>
* * * * * </ArticleMisc>
* * * *</ArticleMiscs>
</Location>

<Location>
* * * * * <ArticleDescription>
* * * * * * <Description>Shirt Hawaii</Description>
* * * * * *</ArticleDescription>
* * * * <ArticleMiscs>
* * * * * <ArticleMisc>
* * * * * * <Country>GBR</art:Country>
* * * * * * <Size>6</art:Size>
* * * * * </ArticleMisc>
* * * *</ArticleMiscs>
</Location>

So the original file contains 3 "ArticleMisc" Sections per <Location>,
the tranformed one only one Misc per Location. Can anybody give me a
hint how this van be done via XSLT?

Thanks,

Jens
Jul 15 '08 #2
Great! Thanks a lot!

msbalaji <msbal...@india.comwrote:
Hi,

try this code

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Location">
<xsl:for-each select="//ArticleMisc">
<Location>
<xsl:copy-of select="../../ArticleDescription"/>
<ArticleMiscs>
<xsl:copy-of select="."/>
</ArticleMiscs>
</Location>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Regards,
Balaji. M
sql-ebooks.blogspot.com

On Jul 15, 11:56*am, Jens Hofmeier <aaaa111...@discardmail.comwrote:
Hi,
i am quite new to xml and need to transform an existing xml file:
<Location>
* * * * * <ArticleDescription>
* * * * * * <Description>Shirt Hawaii</Description>
* * * * * *</ArticleDescription>
* * * * <ArticleMiscs>
* * * * * <ArticleMisc>
* * * * * * <Country>DEU</Country>
* * * * * * <Size>32</Size>
* * * * * </ArticleMisc>
* * * * * <art:ArticleMisc>
* * * * * * <Country>USA</art:Country>
* * * * * * <Size>XS</art:Size>
* * * * * </ArticleMisc>
* * * * * <ArticleMisc>
* * * * * * <Country>GBR</art:Country>
* * * * * * <Size>6</art:Size>
* * * * * </ArticleMisc>
* * * * *</ArticleMiscs>
</Location>
this should be transformed to:
<Location>
* * * * * <ArticleDescription>
* * * * * * <Description>Shirt Hawaii</Description>
* * * * * *</ArticleDescription>
* * * * <ArticleMiscs>
* * * * * <ArticleMisc>
* * * * * * <Country>DEU</Country>
* * * * * * <Size>32</Size>
* * * * * </ArticleMisc>
* * * *</ArticleMiscs>
</Location>
<Location>
* * * * * *<ArticleDescription>
* * * * * * <Description>Shirt Hawaii</Description>
* * * * * *</ArticleDescription>
* * * * <ArticleMiscs>
* * * * * *<ArticleMisc>
* * * * * * <Country>USA</art:Country>
* * * * * * <Size>XS</art:Size>
* * * * * </ArticleMisc>
* * * *</ArticleMiscs>
</Location>
<Location>
* * * * * <ArticleDescription>
* * * * * * <Description>Shirt Hawaii</Description>
* * * * * *</ArticleDescription>
* * * * <ArticleMiscs>
* * * * * <ArticleMisc>
* * * * * * <Country>GBR</art:Country>
* * * * * * <Size>6</art:Size>
* * * * * </ArticleMisc>
* * * *</ArticleMiscs>
</Location>
So the original file contains 3 "ArticleMisc" Sections per <Location>,
the tranformed one only one Misc per Location. Can anybody give me a
hint how this van be done via XSLT?
Thanks,
Je
Jul 15 '08 #3

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

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
12
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
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...
4
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x =...
5
by: shauldar | last post by:
Is there a way (tool, hack...) to create an XSL:FO from an XSLT + XML files? My motivation is that we want to use a tool to design reports, and from that "design" generate both HTML (via XSLT)...
6
by: JJBean | last post by:
Hi Oleg and All, Is this correct? Can I do this? <code> XmlDocument doc=new XmlDocument(); XPathNavigator nav = doc.CreateNavigator(); //Load the xml file. Change path if needed...
4
by: simon.a.hulbert | last post by:
Hi, I'm trying to view the following xslt transformation using firefox <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" > <xsl:output method = "xml" indent =...
2
by: Jonny B | last post by:
Hi all, I'm working on an a clientside xslt using jscript that passes a parameter to the xsl. I've got it working no problem in IE but cant get it to work in Mozilla. Can anyone help? This is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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.