473,806 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1870
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*******@bigfo ot.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('student s',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.go ogle.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('student s',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
1767
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 FieldType nodes. Notice that the fieldTypeCode nodes match in value. I need to pass in a fieldTypeCode (fieldTypeCode='1') to a template which will iterate through the Extension nodes and display the reportable Amount. I also need to do the same thing...
3
2819
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 created 4 different stylesheets. Two of them are working as expected. The other two are printing out the correct values to the result file but are also including all my CDATA information from elements that do not match the template match clause....
3
4210
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> <name>super</name> <sells> <drink>squash</drink>
3
7623
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> <data2>fdas</data2>
7
2293
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 preceeded by an aml:annotation element (whose @w:type is 'Word.Bookmark.Start').
5
1320
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 </xsl:template>
9
2119
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
1596
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
2058
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 - remove all "a" elements which, as a result of "b" element removal, now have no children so, starting with:
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9598
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
10371
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
10373
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
10111
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
6877
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
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.