473,399 Members | 3,038 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,399 software developers and data experts.

XSLT Help

I've a project where the XML should be transformed.

If a tag exists in Output and Parameters, the Parameters one should be
replaced by the Output corresponding and its childs.

Example: (XML In):

<RESULT>
<PARAMETERS>
<CYCLE>
<ENDDATE></ENDDATE>
<NUMBER>50</NUMBER>
</CYCLE>
<FILE>
<CHECK>Yes</CHECK>
</FILE>
<DIR>
<NAME>ONE</NAME>
</DIR>
<RUNTYPE>SAMPLE</RUNTYPE>
</PARAMETERS>
<OUTPUT jobfactor="71">
<CYCLE>
<NAME>MARY<\NAME>
<SURNAME>ROSE<\SURNAME>
</CYCLE>
<FILE>
<FILENAME>E:\ftphome\vodafone\xml\CC20060215S50.XM L</FILENAME>
</FILE>
</OUTPUT>
</RESULT>

(XML Out):

<PARAMETERS>
<CYCLE>
<NAME>MARY<\NAME>
<SURNAME>ROSE<\SURNAME>
</CYCLE>
<FILE>
<FILENAME>E:\ftphome\vodafone\xml\CC20060215S50.XM L</FILENAME>
</FILE>
<DIR>
<NAME>ONE</NAME>
</DIR>
<RUNTYPE>SAMPLE</RUNTYPE>
</PARAMETERS>

I've done somtehing like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0"
encoding="iso-8859-1"></xsl:output>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="OUTPUT"></xsl:template>
<xsl:template match="/RESULT/PARAMETERS/FILE">
<xsl:copy-of select="/RESULT/OUTPUT/FILE" />
</xsl:template>
</xsl:stylesheet>

but this only works if FILE exists, it is not generic. Might you help
me, please?

Its urgent.

Mar 9 '06 #1
3 1214

ca************@gmail.com wrote:
If a tag exists in Output and Parameters, the Parameters one should be
replaced by the Output corresponding and its childs.


It's impossible to answer this because you haven't defined what
"corresponds" means, Usually a problem like this has an id attribute
somewhere and it's a question of writing predicates that either match,
or exclude elements with matching ids.

In your example, is "correspondence" just based on position? Can there
be more than one "Output" or "Parameter" in the document ?

Tell us what "corresponds" means, and we can probably help you.

Mar 9 '06 #2
Thank you in advance.

If and only if a tag from Parameters, exists in Output (with the same
name). This tag in Output should overwrite the tag with the same name
in Parameters.

<Parameters>
<A>
<B>One<B/>
<A/>
<D>
<E>Three<E/>
<D/>
<Parameters/>
<Output>
<A>
<C>Two<C/>
<A>
<Output/>

the XSLT should transforms it into:

<Parameters>
<A>
<C>Two<C/>
<A/>
<D>
<E>Three<E/>
<D/>
<Parameters/>

The A tag (and its childs) were copied from Output into Parameters.

Mar 9 '06 #3
ca************@gmail.com wrote:
Thank you in advance.

If and only if a tag from Parameters, exists in Output (with the same
name). This tag in Output should overwrite the tag with the same name
in Parameters.

<Parameters>
<A>
<B>One<B/>
<A/>
<D>
<E>Three<E/>
<D/>
<Parameters/>
<Output>
<A>
<C>Two<C/>
<A>
<Output/>
That isn't XML. Your end-tags are all defective.
the XSLT should transforms it into:

<Parameters>
<A>
<C>Two<C/>
<A/>
<D>
<E>Three<E/>
<D/>
<Parameters/>

The A tag (and its childs) were copied from Output into Parameters.


Assuming you fix up your file, try this.

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

<xsl:output method="xml"/>

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

<xsl:template match="Parameters/*">
<xsl:choose>
<xsl:when test="../../Output/*[name()=current()/name()]">
<xsl:copy-of select="../../Output/*[name()=current()/name()]"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Mar 9 '06 #4

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

Similar topics

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...
1
by: Victor | last post by:
Hi, this might sound silly but I cannot figure out how to incorporate some XML of employees into some XML of a company to give new XML containing them all. For example, this is the company now ...
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...
5
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating...
4
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
4
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
15
by: Jeff Uchtman | last post by:
Can I draw from 2 XML sources, the structure is exactly the same execpt for data contained into 1 xslt using math to add some structrure, and displaying others as node 1 and node 2? This data 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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
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.