Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes select first child element values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "select first child element values" Watch "select first child element values" New topic
Author

select first child element values

kiran kumar
Greenhorn

Joined: Apr 04, 2006
Posts: 27
I am newbie to xslt, just a day old.

i have a xml file like this

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="C:/Documents and Settings/nbk8paw/Desktop/Capture Activity By Card Type/cvsraw1.xsl"?>
<RowSet>
<Row>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
</Row>
<Row>
<MID>3896025600000513</MID>
<MCC>8011</MCC>
<Merch_Name>LINCOLN PARK FAMILY PHYSICIANS</Merch_Name>
<Merch_City>CHICAGO</Merch_City>
<Merch_Zip>606141207</Merch_Zip>
<Merch_State>IL</Merch_State>
<RunDate>4/14/2006</RunDate>
<Bank>3896</Bank>
<Rpt_ID>C101C</Rpt_ID>
<Rpt_Start_Date>10/01/2005</Rpt_Start_Date>
<Rpt_End_Date>03/01/2006</Rpt_End_Date>
<Rpt_Title>Capture Activity By Card Type</Rpt_Title>

<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
<Trans>
<POS_Entry>90-Swiped</POS_Entry>
<Tran_Amt>$20.00</Tran_Amt>
<CardHolder_Num>4782001005905413 </CardHolder_Num>
<Tran_Date>02/24/2006</Tran_Date>
<Tran_Time>12:02</Tran_Time>
<Auth_CD>060710</Auth_CD>
<Ref_Num>00889 </Ref_Num>
<Inv_Num></Inv_Num>
<Auth_Amt>$20.00</Auth_Amt>
<Tran_Descr>-Sale</Tran_Descr>
</Trans>
<Trans>
<POS_Entry>90-Swiped</POS_Entry>
<Tran_Amt>$10.00</Tran_Amt>
<CardHolder_Num>4782001005593201 </CardHolder_Num>
<Tran_Date>02/24/2006</Tran_Date>
<Tran_Time>12:02</Tran_Time>
<Auth_CD>010715</Auth_CD>
<Ref_Num>00889 </Ref_Num>
<Inv_Num></Inv_Num>
<Auth_Amt>$10.00</Auth_Amt>
<Tran_Descr>-Sale</Tran_Descr>
</Trans>
<Trans>
<POS_Entry>90-Swiped</POS_Entry>
<Tran_Amt>$20.00</Tran_Amt>
<CardHolder_Num>4720460020899388 </CardHolder_Num>
<Tran_Date>02/24/2006</Tran_Date>
<Tran_Time>12:02</Tran_Time>
<Auth_CD>619862</Auth_CD>
<Ref_Num>00889 </Ref_Num>
<Inv_Num></Inv_Num>
<Auth_Amt>$20.00</Auth_Amt>
<Tran_Descr>-Sale</Tran_Descr>
</Trans>
<Trans>
<POS_Entry>90-Swiped</POS_Entry>
<Tran_Amt>$20.00</Tran_Amt>
<CardHolder_Num>4782001004243576 </CardHolder_Num>
<Tran_Date>02/24/2006</Tran_Date>
<Tran_Time>12:02</Tran_Time>
<Auth_CD>085613</Auth_CD>
<Ref_Num>00889 </Ref_Num>
<Inv_Num></Inv_Num>
<Auth_Amt>$20.00</Auth_Amt>
<Tran_Descr>-Sale</Tran_Descr>
</Trans>
<Trans>
<POS_Entry>90-Swiped</POS_Entry>
<Tran_Amt>$20.00</Tran_Amt>
<CardHolder_Num>4385110700026796 </CardHolder_Num>
<Tran_Date>02/24/2006</Tran_Date>
<Tran_Time>12:02</Tran_Time>
<Auth_CD>721901</Auth_CD>
<Ref_Num>00889 </Ref_Num>
<Inv_Num></Inv_Num>
<Auth_Amt>$20.00</Auth_Amt>
<Tran_Descr>-Sale</Tran_Descr>
</Trans>
<Trans>
<POS_Entry>90-Swiped</POS_Entry>
<Tran_Amt>$20.00</Tran_Amt>
<CardHolder_Num>4264299459270204 </CardHolder_Num>
<Tran_Date>02/24/2006</Tran_Date>
<Tran_Time>12:02</Tran_Time>
<Auth_CD>05509A</Auth_CD>
<Ref_Num>00889 </Ref_Num>
<Inv_Num></Inv_Num>
<Auth_Amt>$20.00</Auth_Amt>
<Tran_Descr>-Sale</Tran_Descr>
</Trans>
<Trans></Trans>
<Trans></Trans>
<Trans>
<POS_Entry>90-Swiped</POS_Entry>
<Tran_Amt>$15.00</Tran_Amt>
<CardHolder_Num>5491139051734409 </CardHolder_Num>
<Tran_Date>02/24/2006</Tran_Date>
<Tran_Time>12:02</Tran_Time>
<Auth_CD>068235</Auth_CD>
<Ref_Num>00889 </Ref_Num>
<Inv_Num></Inv_Num>
<Auth_Amt>$15.00</Auth_Amt>
<Tran_Descr>-Sale</Tran_Descr>
</Trans>
<Trans>
<POS_Entry>90-Swiped</POS_Entry>
<Tran_Amt>$35.00</Tran_Amt>
<CardHolder_Num>5416600046950402 </CardHolder_Num>
<Tran_Date>02/24/2006</Tran_Date>
<Tran_Time>12:02</Tran_Time>
<Auth_CD>024641</Auth_CD>
<Ref_Num>00889 </Ref_Num>
<Inv_Num></Inv_Num>
<Auth_Amt>$35.00</Auth_Amt>
<Tran_Descr>-Sale</Tran_Descr>
</Trans>
<Trans></Trans>
<Trans></Trans>
<Trans></Trans>
</Row>
</RowSet>


I want to select only the first child elements of the Row.
that is <MID></MID>
<MCC></MCC>
<Merch_Name></Merch_Name>
<Merch_City></Merch_City>
<Merch_Zip></Merch_Zip>
<Merch_State></Merch_State>
<RunDate></RunDate>
<Bank></Bank>
<Rpt_ID></Rpt_ID>
<Rpt_Start_Date></Rpt_Start_Date>
<Rpt_End_Date></Rpt_End_Date>
<Rpt_Title></Rpt_Title>
i dont want to hardcode but i want to fetch if the values of the first child. Does any of you have the solution for this.

i greatly appreciate for the help.

thanks in advance
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18153
    
    8

Was the example you gave supposed to be what you want as output? Because it isn't anything like the description you gave. The first element children of your Row elements are just

<Trans></Trans>
<MID>3896025600000513</MID>

I don't know how to describe your example at all. You don't seem to want Trans elements. And you seem to want the elements you do want to have no text children. So, sorry, I don't get it. Could you try a different explanation?
kiran kumar
Greenhorn

Joined: Apr 04, 2006
Posts: 27
Hello Paul,
The final output that i want is

Row/mid,row/mcc, row/merchantname, .. row/trans1/pos_entry, row/trans/tran_amt,...

Row/mid,row/mcc, row/merchantname, .. row/trans2/pos_entry, row/trans2/tran_amt,...

We have 1 row and say 10 trans
i want row, tran1
row trans2
row trans3
row transn
hope i am clear this time.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18153
    
    8

Originally posted by Kranti Aella:
hope i am clear this time.
No. You just provide an incomplete list of elements you want. (At least I think you want the elements, it's not clear.) They look arbitrary to me. There is no way to guess what "..." means.

Okay, let's pick an element at random.

<Tran_Date>02/24/2006</Tran_Date>

Do you want to write this element to the output? If so, why? If not, why not? And do you want just the start and end tags, or do you want the text content as well, or just the text content?
kiran kumar
Greenhorn

Joined: Apr 04, 2006
Posts: 27
Paul thanks for your intrest to help me.
I could finally achieve the ouput what i wanted. I wanted to retreive all the text of "for each ROW element print the text of all childs of "ROW" and text of elements of Trans[0]"

Row
-child
-child
-child
-Trans1
- Tchild11
-Tchild 12
-Trans2
-Trans21
-Trans22

i wanted output like
child child child Tchild11 Tchild12
child child child Tchild21 Tchild22

onceagin i really appreciate you for your intrest to help.
 
Don't get me started about those stupid light bulbs.
 
subject: select first child element values
 
Similar Threads
need help on debugging jsp
Mulitple fo:page-sequence
DYNAMIC LIST BOX
looping xsl
Map Summation