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 get the first familyjudgement from xml doc? 1

Status
Not open for further replies.

momo2000

Programmer
Jan 2, 2015
63
0
0
US
I would like to output the first FamilyJudgement from my xml document. How do I do it?

Expected output
XML:
<FamilyJudgment judgmentKey="3928551">
	<JudgmentEventTypeText>Custody order</JudgmentEventTypeText>
</FamilyJudgment>

xml document
XML:
<?xml version="1.0" encoding="UTF-8"?>
<CaseNotification>
	<CourtDecisionNotification>
		<TriggeredDateTime>2016-07-12T15:05:45-05:00</TriggeredDateTime>
		<NotificationEvent>CourtDecisionModified</NotificationEvent>
		<FamilyJudgment judgmentKey="3928551">
			<JudgmentEventTypeText>Custody order</JudgmentEventTypeText>
			<JudgmentEventDate>2016-07-12</JudgmentEventDate>
			<Custody>
				<CustodyDescriptionText>Legal custody</CustodyDescriptionText>
			</Custody>
		</FamilyJudgment>
		<FamilyJudgment judgmentKey="3928551">
			<JudgmentEventTypeText>Custody order</JudgmentEventTypeText>
			<JudgmentEventDate>2016-07-12</JudgmentEventDate>
			<Custody>
				<CustodyDescriptionText>Legal custody</CustodyDescriptionText>
			</Custody>
		</FamilyJudgment>
	</CourtDecisionNotification>
</CaseNotification>
 
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
  version="1.0">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="node() | @*">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="FamilyJudgment[position() = 1]">
    <xsl:copy>
      <xsl:copy-of select="@* | child::*[1]"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
 
I would make the following suggested change to make the template less dependent on the position of the desired <JudgementEventTypeText> element (and perhaps a bit less obscure - XPath being obscure enough already).

Code:
<xsl:template match="FamilyJudgment[position() = 1]">
    <xsl:copy>
      <xsl:copy-of select="@* | JudgementEventTypeText"/>
    </xsl:copy>
</xsl:template>

Given that I also work with LegalXML (and Tyler's substitutions), I know there are many optional fields in the schema. I would never recommend using an absolute position instead of an element name when a particular element is desired.

Note that this differs from your business rule that you want the first FamilyJudgement element. In that situation, [tt][position() = 1][/tt] (or more simply [tt][1][/tt]) is appropriate.

Tom Morrison
Hill Country Software
 
Tom, that is a very sound advice (with a personal benefit of learn about LegalXML).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top