Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I return correct event elements 1

Status
Not open for further replies.

momo2000

Programmer
Jan 2, 2015
63
0
0
US
I have a xml 1.0 document with 3 JudgmentEvent.
What I would like to get as output is
1. JudgmentEvent whose parent have not been deleted.
2. JudgmentEvent that have no parent and they have not been deleted.

I do not know how to do this.

My output should look like this:
XML:
<JudgmentEvent ID="207217600">
	<JudgmentEventType>Judgment - not all parties</JudgmentEventType>
	<Judgment ID="3928438"/>
</JudgmentEvent>
<JudgmentEvent ID="207218513">
	<JudgmentEventType>Adopted</JudgmentEventType>
	<Judgment ID="3928452"/>
</JudgmentEvent>

The reason I should get
XML:
<Judgment ID="3928438" InternalID="1613120226"/>
is because this has amended
XML:
<Judgment ID="3928436" InternalID="1613120224"/>
.

xml 1.0 code
XML:
<?xml version="1.0" encoding="UTF-8"?>
<Case>
	<JudgmentEvent InternalID="1810327075" ID="207217512" Date="05/24/2016">
		<JudgmentEventType InternalID="51314" Word="JDGMULT">Judgment - not all parties</JudgmentEventType>
		<IssueDate>05/24/2016</IssueDate>
		<TimestampCreate>05/24/2016 09:32:50:837</TimestampCreate>
		<TimestampChange>05/24/2016 11:34:15</TimestampChange>
		<Deleted>true</Deleted>
		<AmendReason InternalID="11091" Word="CTORDER">Court Order</AmendReason>
		<Judgment ID="3928437" InternalID="1613120225"/>
		<JudgmentEvent InternalID="1810327074" ID="207217511" Date="05/24/2016">
			<JudgmentEventType InternalID="13024" Word="JUDGGR">Judgment</JudgmentEventType>
			<IssueDate>05/24/2016</IssueDate>
			<AgingClockActionKey Word="SP">Stops case aging clock</AgingClockActionKey>
			<TimestampCreate>05/24/2016 09:32:24:447</TimestampCreate>
			<TimestampChange>05/24/2016 11:51:29</TimestampChange>
			<Deleted>false</Deleted>
			<Judgment ID="3928436" InternalID="1613120224"/>
		</JudgmentEvent>
	</JudgmentEvent>
	<JudgmentEvent InternalID="1810327167" ID="207217600" Date="05/24/2016">
		<JudgmentEventType InternalID="51314" Word="JDGMULT">Judgment - not all parties</JudgmentEventType>
		<IssueDate>05/24/2016</IssueDate>
		<TimestampCreate>05/24/2016 11:51:29:377</TimestampCreate>
		<Deleted>false</Deleted>
		<AmendReason InternalID="11091" Word="CTORDER">Court Order</AmendReason>
		<Judgment ID="3928438" InternalID="1613120226"/>
		<JudgmentEvent InternalID="1810327074" ID="207217511" Date="05/24/2016">
			<JudgmentEventType InternalID="13024" Word="JUDGGR">Judgment</JudgmentEventType>
			<IssueDate>05/24/2016</IssueDate>
			<TimestampCreate>05/24/2016 09:32:24:447</TimestampCreate>
			<TimestampChange>05/24/2016 11:51:29</TimestampChange>
			<Deleted>false</Deleted>
			<RecordingNeeded>false</RecordingNeeded>
			<Judgment ID="3928436" InternalID="1613120224"/>
		</JudgmentEvent>
	</JudgmentEvent>
	<JudgmentEvent InternalID="1810327321" ID="207218513" Date="05/25/2016">
		<JudgmentEventType InternalID="12997" Word="ADOPT">Adopted</JudgmentEventType>
		<IssueDate>05/25/2016</IssueDate>
		<TimestampCreate>05/25/2016 10:35:01:210</TimestampCreate>
		<Deleted>false</Deleted>
		<Judgment ID="3928452" InternalID="1613120240"/>
	</JudgmentEvent>
</Case>
 
Restating:

You wish to select all JudgementEvent nodes where:
[ul]
[li]the parent is a JudgementEvent node which does not contain as a child a Deleted node which has true as its text value; as well as[/li]
[li]the Parent is not a JudgementEvent node, and no child Deleted node the text value of which is true[/li]
[/ul]

I wil make the simplifying assumption, based on your example, that all JudgementEvent nodes have a child node named Deleted.

The Xpath expression for the first item is:
Code:
//JudgementEvent[parent::JudgementEvent][../Deleted != 'true']

The XPath expression for the second item is:
Code:
//JudgementEvent[local-name(..) != 'JudgementEvent'][Deleted != 'true']

The vertical bar ( | ) is the union operator. So to select the union of these two sets:
Code:
//JudgementEvent[parent::JudgementEvent][../Deleted != 'true'] | 
//JudgementEvent[local-name(..) != 'JudgementEvent'][Deleted != 'true']

WARNING: Typed, not tested.

XSLT left as an exercise.

Tom Morrison
Hill Country Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top