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

Matching values of nodes to apply templates

Hi All
I will try to explain my problem.

I am wishing to apply a template to the following XML. There are
multiple event nodes within the register root node. For each of the
event nodes there are a list of students taking the Event. I wish to
apply a template (and thus get the data) for the same student across
the events. I can apply the template to student 18 for event 1, how
do i then get the data for student 18 from event 2 and then for event
3 and so on?

Many thanks in advance.

David
<register>
<event>
<code>1</code>
<date>...</date>
Jul 20 '05 #1
5 1851
I can apply the template to student 18 for event 1, how
do i then get the data for student 18 from event 2 and then for event
3 and so on?


<xsl:apply-templates select="event/student[code=18]"/>

will apply templates to student elements with code=18 whatever event
they are in.

David
Jul 20 '05 #2
David Carlisle <da****@nag.co.uk> wrote in message news:<yg*************@penguin.nag.co.uk>...
I can apply the template to student 18 for event 1, how
do i then get the data for student 18 from event 2 and then for event
3 and so on?


<xsl:apply-templates select="event/student[code=18]"/>

will apply templates to student elements with code=18 whatever event
they are in.

David


Thanks for this.

The problem that I can forsee with this is that i dont actually know
the students code.
I need to show a line of details for each student. There will be
different numbers of students with different codes per print out.

Thanks

David
Jul 20 '05 #3
dh*******@bigfoot.com (david hepworth) writes:
David Carlisle <da****@nag.co.uk> wrote in message news:<yg*************@penguin.nag.co.uk>...
I can apply the template to student 18 for event 1, how
do i then get the data for student 18 from event 2 and then for event
3 and so on?


<xsl:apply-templates select="event/student[code=18]"/>

will apply templates to student elements with code=18 whatever event
they are in.

David


Thanks for this.

The problem that I can forsee with this is that i dont actually know
the students code.
I need to show a line of details for each student. There will be
different numbers of students with different codes per print out.

Thanks

David

just replace the literal 18 in the code I posted with whatever code you
need to calculate the value. (Or perhaps simpler calcualte teh value
first in a variable, and use a variable reference instead of 18)
Jul 20 '05 #4
> I am wishing to apply a template to the following XML. There are
multiple event nodes within the register root node. For each of the
event nodes there are a list of students taking the Event. I wish to
apply a template (and thus get the data) for the same student across
the events. I can apply the template to student 18 for event 1, how
do i then get the data for student 18 from event 2 and then for event
3 and so on?


Hi,

I think this might be a way to the solution of your problem.

<xsl:key name="students" match="student/code" use="."/>

<xsl:template match="/">
<xsl:apply-templates select="//student[generate-id(code) =
generate-id(key('students',code))]">
<xsl:sort select="name"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="student">
student name: <xsl:value-of select="name"/>
<xsl:apply-templates select="//event[student/code=current()/code]"/>
</xsl:template>

<xsl:template match="event">
event: <xsl:value-of select="code"/>
</xsl:template>

this code produces:

student name: Janet Bloggs
event: 1
event: 2
student name: Joe Bloggs
event: 1
event: 2

Is this useful?
Joris Gillis

--
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #5
ro**@pandora.be (Joris Gillis) wrote in message news:<a4**************************@posting.google. com>...
I am wishing to apply a template to the following XML. There are
multiple event nodes within the register root node. For each of the
event nodes there are a list of students taking the Event. I wish to
apply a template (and thus get the data) for the same student across
the events. I can apply the template to student 18 for event 1, how
do i then get the data for student 18 from event 2 and then for event
3 and so on?


Hi,

I think this might be a way to the solution of your problem.

<xsl:key name="students" match="student/code" use="."/>

<xsl:template match="/">
<xsl:apply-templates select="//student[generate-id(code) =
generate-id(key('students',code))]">
<xsl:sort select="name"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="student">
student name: <xsl:value-of select="name"/>
<xsl:apply-templates select="//event[student/code=current()/code]"/>
</xsl:template>

<xsl:template match="event">
event: <xsl:value-of select="code"/>
</xsl:template>

this code produces:

student name: Janet Bloggs
event: 1
event: 2
student name: Joe Bloggs
event: 1
event: 2

Is this useful?
Joris Gillis


Many thanks to both of you for your help - I believe that this will work.
David
Jul 20 '05 #6

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

Similar topics

2
by: johkar | last post by:
I need a hint (a big hint) on how to use XSL variables and parameters. It is definitely not clicking yet. Below is my XML stripped down. There are multiple Extension nodes and multiple...
3
by: Shannon Hughes | last post by:
I created a simple 7 line stylesheet in XML Spy that is matching certain elements (table names) used to created some SQL syntax in the result file. I had to do this for 4 different Elements so I...
3
by: Simon | last post by:
Hi, I have generated an xml document, and would like to be able to transform it to another such that the contents of a chosen node type are flattened (i.e. tags removed). e.g. <shop>...
3
by: Michael | last post by:
Hello, I am creating an XSL that is going to create a report from XML we recieve from another system. The XML would look like: <report> <page> <header1> <data1>asdf</data1>...
7
by: Bill Cohagan | last post by:
I have an XSLT transformation that involves a template with match = "w:p]" What I'm matching on is a w:p element that is: 1.) Within a w:body element (at some level). 2.) Immediately...
5
by: Daniel Frey | last post by:
Hello I'd like to match a dynamic node, given as a parameter to the stylesheet. Something like: <xsl:stylesheet ...> <xsl:param name="tomatch"/> <xsl:template match="{$tomatch}"> Hallo...
9
by: gregmcmullinjr | last post by:
Hello, I am new to the concept of XSL and am looking for some assistance. Take the following XML document: <binder> <author>Greg</author> <notes> <time>11:45</time>
4
by: patrik.nyman | last post by:
Hi! I have elements like these: <name style="it">SomeData</name> <otherName style="it">SomeOtherData</otherName> and tries to transform these with the following: <xsl:template match="*">
3
by: tschwartz | last post by:
I'm trying to write a stylesheet which removes nodes which are empty as a result of other template processing. For example, given the following xml, I'd like to: - remove all "b" elements -...
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: 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
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
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.