Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2007, 04:44 AM
Registered User
 
Join Date: Oct 2007
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
 
Old October 26th, 2007, 05:39 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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





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 09:34 AM
To get a list of specific tag from xml using v JelfMaria VB How-To 0 January 11th, 2005 07:21 AM
creating a form tag in code marciapz ASP.NET 1.0 and 1.1 Professional 6 August 1st, 2003 06:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.