473,786 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT loop.

Hi all,

I am try to split the some data out of a nested xml file and get all the
data in one new xml file. I have two XSLT files one takes the personal
information and one takes the data out of the fund section , then I import
each xml files into the datebase and do I relationship between the two.
This is not what my boss wants as he wants one xml file

This is my current XML

<message>
<personal>
<forenames>John </forenames>
<surname>Smit h</surname>
<policynumber>1 23456</policynumber>
<person>
<policydetail s>
<fund>
<code>ABC</code>
<units>123</units>
</fund>
<fund>
<code>xyz</code>
<units>987</units>
</fund>
</policydetails>
</message>

and I am trying to acheive this

<message>
<personal>
<forenames>John </forenames>
<surname>Smit h</surname>
<policynumber>1 23456</policynumber>
<person>
<policydetail s>
<fund>
<code>ABC</code>
<units>123</units>
</fund>
</policydetails>
<personal>
<forenames>John </forenames>
<surname>Smit h</surname>
<policynumber>1 23456</policynumber>
<person>
<policydetail s>
<fund>
<code>xyz</code>
<units>987</units>
</fund>
</policydetails>
</message>

I have been trying with <xsl:for-each> looping through personal and
policydetails but am getting some strange results!! Can somebody please
point me in the right direction.

TIA
Apr 5 '06 #1
4 2211
It's hard to offer advice without knowing details of what your
stylesheet looks like. Can you come up with a minimal example that
demonstrates the problem?
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 5 '06 #2
Here is the stylesheet.

<xsl:for-each select="message/fund">

<xsl:for-each select="message ">

<xsl:element name="details">
<xsl:element name="forenames "><xsl:valu e-of
select="//forenames"></xsl:value-of>
<xsl:element name="forenames "><xsl:valu e-of
select="//surnames"></xsl:value-of>
<xsl:element name="forenames "><xsl:valu e-of
select="//policynumber"></xsl:value-of>

<xsl:element name="forenames "><xsl:valu e-of
select="//fund"></xsl:value-of>
<xsl:element name="forenames "><xsl:valu e-of
select="//code"></xsl:value-of>
<xsl:element name="forenames "><xsl:valu e-of
select="//units"></xsl:value-of>
</xsl:element>

</xsl:for-each>

</xsl:for-each>

"Joe Kesselman" <ke************ @comcast.net> wrote in message
news:n9******** *************** *******@comcast .com...
It's hard to offer advice without knowing details of what your stylesheet
looks like. Can you come up with a minimal example that demonstrates the
problem?

Apr 5 '06 #3
Iain wrote:
I have been trying with <xsl:for-each> looping through personal and
policydetails but am getting some strange results!! Can somebody please
point me in the right direction.


<xsl:template match="message" >
<xsl:copy>
<xsl:for-each select="policyd etails/fund" >

<xsl:copy-of select="../preceding-sibling::person al [1]" />

<policydetail s>
<xsl:copy-of select="." />
</policydetails>
</xsl:for-each>
</xsl:copy>
</xsl:template>
This is two loops, one (implicit) for <message> and an explicit one for
<fnud>
We don't try to "synchronis e" loops for people and funds, that never
works in XSLT. Instead we loop over whatever has the ordinal
relationship, then extract the dependent part (the <personal> with a
lookup).

There's also a typo in your XML <personal> / <person> and I don't like
its structure anyway. If <message> ever contains multiple <personal>s,
then you're relying on the _ordering_ of XML, not the nesting.
Personally this always makes me nervous.

Apr 5 '06 #4

<di*****@codesm iths.com> wrote in message
news:11******** ************@v4 6g2000cwv.googl egroups.com...
Iain wrote:
I have been trying with <xsl:for-each> looping through personal and
policydetails but am getting some strange results!! Can somebody please
point me in the right direction.
<xsl:template match="message" >
<xsl:copy>
<xsl:for-each select="policyd etails/fund" >

<xsl:copy-of select="../preceding-sibling::person al [1]" />

<policydetail s>
<xsl:copy-of select="." />
</policydetails>
</xsl:for-each>
</xsl:copy>
</xsl:template>
This is two loops, one (implicit) for <message> and an explicit one for
<fnud>
We don't try to "synchronis e" loops for people and funds, that never
works in XSLT. Instead we loop over whatever has the ordinal
relationship, then extract the dependent part (the <personal> with a
lookup).

There's also a typo in your XML <personal> / <person> and I don't like
its structure anyway. If <message> ever contains multiple <personal>s,
then you're relying on the _ordering_ of XML, not the nesting.
Personally this always makes me nervous.


Many thanks. This worked a treat.

If <message> ever contains multiple <personal>s,
then you're relying on the _ordering_ of XML, not the nesting.
Personally this always makes me nervous.


I agree and understand. However I am limited to how the XML is structured
by the Filemaker database I need to import the data into.
Apr 5 '06 #5

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

Similar topics

3
2126
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim is to process the contacts in a single-pass XSLT process. That is why the "document()" function is what I need. I call the "document()" XPath function from a "for-each" instruction.
1
1563
by: Oleg Konovalov | last post by:
Hi, I am new to XSLT, modifying somebody else's code: I have the following data (leaves in parallel branches): mystruct/myarray1/myvar/var2 and mystruct/myarray2/myvar/var3 I need to implement the find the first occurence of : <xsl:if test="position() != last() and
6
3522
by: utterberg | last post by:
Hi, I've got an xml that looks like this: <section name="Risk"> <label>RISK MANAGEMENT (RM)</label> <field name="RM.1"> <ref>RM.1</ref> <label>Text goes here...</label> <option value="2">Yes</option> <option value="1">No</option> <option value="0">-</option>
5
1604
by: Patrick.O.Ige | last post by:
I have an xml and i'm trying to loop each node... When i do FOR EACH i seem not to get my desired result I want to loop through and get only the values that matches the question i specified with the corresponding answers? I don't want to retrieve all the Answer and VoteAnswers nodes <xsl:for-each select="NSurveyVoter/Voter/Question/Answer"> <xsl:value-of select="Answer/Answer/text()"/>
1
1646
by: jrwarwick | last post by:
Hello, I believe I have uncovered a bug in the .Net XSLT engine to do with 'for' loops in XSLT. Here are the steps to reproduce it: -Create A new webform project. -Add the xml file 'errorexample.xml' - it is shown at the bottom -Add the xslt file 'errorexample.xslt' - it is shown at the bottom -Add a label into the WebForm1.aspx designer and stretch it so it is large, give it the ID of Output1. -Import the following namespaces in...
2
7403
by: Scamjunk | last post by:
I have been desperately looking for a treeview-type solution for my problem for the past three weeks and have been greatly unsuccessful. I am totally new to the world of XSLT and I *don't know* JavaScript. Still, I have managed to get something together, which I am putting across here. Any help (even pointing me to the place to look) is welcome. The problem I have is as follows:
18
2087
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 look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1 and A2 and feature B depends on B1 and B2. And write that to a text file.
4
1929
by: shaun roe | last post by:
I should like to count the frequency of strings embedded in a longer string, space separated. Specifically, I have: <phiModule> 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 8 5 5 5 6 6 6 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 9 9 9 9 6 7 7 7 8 8 8 8 9 9 9
1
4748
by: balderdash | last post by:
Hi I am very close to achieving the output I need but I cant seem to get it right. The problem is I am looping through a table and selecting values, if there are 2 values per (row) Issuer I need to put a slash between them in the output xml. The problem is shown by the output at the bottom of this post. I am
3
4655
by: IAMDkg | last post by:
Hi there - Can somebody give me some pointers on how I can create a XSLT which will compile fine but will thow a runtime exception during runtime. I tried to do the following but it doesn't throw any runtime exception. <?xml version='1.0' encoding='utf-8'?> <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/ Transform'>
0
9492
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.