Returns the value of the first name in the first occurrence of the name
element.  Replace the 1 with a 2 to get the second persons first name:
/doc/name[1]/@first  

or this to get a list of all the first names:
/doc/name/@first

To get the first foo element from each, try this

/doc/name/foo[1]

if you want only the first foo from the first occurrence of the name, try
this

/doc/name[1]/foo[1]                                     

For the first and last name from the first occurrence of the name element,
try this:
concat(/doc/name[1]/@first , ' ', /doc/name[1]/@last)

Hope that answered your questions.

Charles

-----Original Message-----
From: Kaushal Sanghavi [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 16, 2003 10:00 PM
To: xalan-c-users
Subject: getting a set of attribute values from xml using c


This is what I'm trying:

I'm just toying with the SerializeNodeSet sample code, and using the foo.xml
as data. I've changed foo.xml to look like this:

<?xml version="1.0"?>
<doc>
  <name first="David" last="Marston">Mr. Marston
   <foo> 123  </foo>
    <foo> 358  </foo>
     <foo> 526  </foo>
  </name>
  <name first="David" last="Bertoni">Mr. Bertoni
   <foo> 1238  </foo>
    <foo> 3585  </foo>
     <foo> 5266  </foo>
     <foo> sjk </foo>
  </name>

  <name first="Donald" last="Leslie">Mr. Leslie</name>
  <name first="Emily" last="Farmer">Ms. Farmer</name>
  <name first="Myriam" last="Midy">Ms. Midy</name>
  <name first="Paul" last="Dick">Mr. Dick</name>
  <name first="Scott" last="Boag">Mr. Boag</name>
  <name first="Shane" last="Curcuru">Mr. Curcuru</name>
  <name first="Joseph" last="Kesselman">Mr. Kesselman</name>
  <name first="Stephen" last="Auriemma">Mr. Auriemma</name>
</doc>

Two questions:
1. I'm trying to get only the value enclosed in the foo element.
(for eg., 123 at the above). Instead, what I'm getting is the following:
bash-2.03$ SerializeNodeSet SerializeNodeSet/foo.xml / //foo
<foo> 123  </foo><foo> 358  </foo><foo> 526  </foo><foo> 1238  </foo><foo>
3585  </foo><foo> 5266  </foo><foo> sjk </foo>

2. I'm trying to get a list of only the first names, i.e. the value stored
in
the attribute "name/@first" . How can I do that.

 - Also, how do I insert a \n or a space, or some de-limiting character
between the results, so I don't get everything as one continous string, as
above?

I'm hoping these will be easy for all the xalan gurus out there! :)

Thanks,
Kaushal

Reply via email to