Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 26th, 2007, 04:44 AM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating a list depending on a tag value

Hi

I have the following xml sample

<MEMBER_DETAILS>
  <FirstName>Aidan J</FirstName>
  <Surname>Smith</Surname>
  <Lifestage>Adult</Lifestage>
  <DateofBirth>09/01/1970</DateofBirth>
  <CoversetHeader>Plan A</CoversetHeader>
    <AMENDMENT_COVER_LIST>
  <Cover />
</AMENDMENT_COVER_LIST>
  <AreaOfCover />
</MEMBER_DETAILS>
   <MEMBER_DETAILS>
  <FirstName>Aine</FirstName>
  <Surname>Smith</Surname>
  <Lifestage>Adult</Lifestage>
  <DateofBirth>09/01/1970</DateofBirth>
  <CoversetHeader>Plan B</CoversetHeader>
   <AMENDMENT_COVER_LIST>
  <Cover />
</AMENDMENT_COVER_LIST>
  <AreaOfCover />
</MEMBER_DETAILS>
<MEMBER_DETAILS>
  <FirstName>Aoife</FirstName>
  <Surname>Smith</Surname>
  <Lifestage>Child</Lifestage>
  <DateofBirth>09/01/2007</DateofBirth>
  <CoversetHeader>Plan A </CoversetHeader>
<AMENDMENT_COVER_LIST>
  <Cover />
</AMENDMENT_COVER_LIST>
  <AreaOfCover />
</MEMBER_DETAILS>

I want to extract the FirstName (and store as a variable) only when the Lifestage tag = 'Adult'

How can this be done?

Thanks



Josephine
Reply With Quote
  #2 (permalink)  
Old October 26th, 2007, 05:39 AM
mhkay's Avatar
Wrox Author
Points: 18,252, Level: 58
Points: 18,252, Level: 58 Points: 18,252, Level: 58 Points: 18,252, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,929
Thanks: 0
Thanked 281 Times in 276 Posts
Default

First let's get some terminology clear. This:

<Lifestage>Adult</Lifestage>

is an element. It has two tags, a start tag and an end tag. It has an element name (or element type name) of "Lifestage", and a value of "Adult". "Adult" is not the value of either of the two tags. This may all seem pedantic, but it's a lot easier to avoid misunderstandings if people use the correct terminology.

It's not clear what your processing context is, but assuming that your context node is the element that is the parent of the MEMBER_DETAILS elements, then I think you want something like

select="MEMBER_DETAILS[Lifestage='Adult']/FirstName"

With your sample data, this path expression will return a node-set containing two elements.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
creating smart tag library Medes VS.NET 2002/2003 0 April 16th, 2006 02:56 PM
creating smart tag library Medes Visual Studio 2005 0 April 10th, 2006 03:29 PM
How to get a list of specific tag from xml using v JelfMaria XML 4 January 13th, 2005 08:34 AM
To get a list of specific tag from xml using v JelfMaria VB How-To 0 January 11th, 2005 06:21 AM
creating a form tag in code marciapz ASP.NET 1.0 and 1.1 Professional 6 August 1st, 2003 06:00 PM



All times are GMT -4. The time now is 10:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.