INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How do I output all charges with with Pending ID?

How do I output all charges with with Pending ID?

How do I output all charges with with Pending ID?

(OP)
I would like to output all Charge elements for all Charges, when OffenseID/ID ID=PENDING.
The important thing to note is that the element <OffenseCite>xyz</OffenseCite will be output as <StatuteNumber>xyz</StatuteNumber>

Sample Output for each Charge should look like this. I did not include all elements

CODE --> xml

<Charge>
<ReportingAgency>xyz</ReportingAgency>
<Statute>
<StatuteDescription>TRAFFIC - DWI - OPERATE MOTOR VEHICLE - ALCOHOL CONCENTRATION 0.08 WITHIN 2 HOURS</StatuteDescription>
<StatuteNumber>169A.20.1(5)</StatuteNumber>
</Statute>
</Charge> 

Input xml doc

CODE --> xml

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns:NS1="http://www.w3.org/2003/05/soap-envelope">
	<Body>
		<TabChargeDocument>

			<Charge>
				<ChargeSequenceID>
					<ID>1</ID>
				</ChargeSequenceID>
				<OffenseID>
					<ID>PENDING</ID>
				</OffenseID>
				<OffenseCite>169A.27.1</OffenseCite>
				<OffenseDescriptionText>TRAFFIC - DWI - FOURTH-DEGREE DRIVING WHILE IMPAIRED; DESCRIBED</OffenseDescriptionText>
				<OffenseDate>2016-09-18</OffenseDate>
				<OffenseTime>00:22:00</OffenseTime>
				<OffenseDatesOnOrAbout>false</OffenseDatesOnOrAbout>
				<SeverityLevelText>Misdemeanor</SeverityLevelText>
				<MinnesotaOffenseCode>NBR</MinnesotaOffenseCode>
				<Report>
					<ReportingAgencyORI>
						<ID>MNMHP0400</ID>
					</ReportingAgencyORI>
					<ReportingAgencyControlNumber>
						<ID>16510299</ID>
					</ReportingAgencyControlNumber>
					<ReportingOfficial>
						<OfficerBadgeNumber>
							<ID>176</ID>
						</OfficerBadgeNumber>
						<OfficerNameText>UTES</OfficerNameText>
					</ReportingOfficial>
				</Report>
				<CommunityOfOffenseText>Brooklyn Park</CommunityOfOffenseText>
			</Charge>
			<Charge>
				<ChargeSequenceID>
					<ID>2</ID>
				</ChargeSequenceID>
				<OffenseID>
					<ID>PENDING</ID>
				</OffenseID>
				<OffenseCite>169A.20.1(5)</OffenseCite>
				<OffenseDescriptionText>TRAFFIC - DWI - OPERATE MOTOR VEHICLE - ALCOHOL CONCENTRATION 0.08 WITHIN 2 HOURS</OffenseDescriptionText>
				<OffenseDate>2016-09-18</OffenseDate>
				<OffenseTime>00:22:00</OffenseTime>
				<OffenseDatesOnOrAbout>false</OffenseDatesOnOrAbout>
				<SeverityLevelText>Misdemeanor</SeverityLevelText>
				<Report>
					<ReportingAgencyORI>
						<ID>MNMHP0400</ID>
					</ReportingAgencyORI>
					<ReportingAgencyControlNumber>
						<ID>16510299</ID>
					</ReportingAgencyControlNumber>
					<ReportingOfficial>
						<OfficerBadgeNumber>
							<ID>176</ID>
						</OfficerBadgeNumber>
						<OfficerNameText>UTES</OfficerNameText>
					</ReportingOfficial>
				</Report>
				<CommunityOfOffenseText>Brooklyn Park</CommunityOfOffenseText>
			</Charge>
			<Charge>
				<ChargeSequenceID>
					<ID>3</ID>
				</ChargeSequenceID>
				<OffenseID>
					<ID>PENDING</ID>/Envelope/Body/TabChargeDocument/Charge[3]/OffenseID/ID
				</OffenseID>
				<OffenseCite>169A.20.1(1)</OffenseCite>
				<OffenseDescriptionText>TRAFFIC - DWI - OPERATE MOTOR VEHICLE UNDER INFLUENCE OF ALCOHOL</OffenseDescriptionText>
				<OffenseDate>2016-09-18</OffenseDate>
				<OffenseTime>00:22:00</OffenseTime>
				<OffenseDatesOnOrAbout>false</OffenseDatesOnOrAbout>
				<SeverityLevelText>Misdemeanor</SeverityLevelText>
				<Report>
					<ReportingAgencyORI>
						<ID>MNMHP0400</ID>
					</ReportingAgencyORI>
					<ReportingAgencyControlNumber>
						<ID>16510299</ID>
					</ReportingAgencyControlNumber>
					<ReportingOfficial>
						<OfficerBadgeNumber>
							<ID>176</ID>
						</OfficerBadgeNumber>
						<OfficerNameText>UTES</OfficerNameText>
					</ReportingOfficial>
				</Report>
				<CommunityOfOffenseText>Brooklyn Park</CommunityOfOffenseText>
			</Charge>
		</TabChargeDocument>
		</Body>
</Envelope> 

RE: How do I output all charges with with Pending ID?

Without an attempt at an XSL, it is unclear what problem you may be having.

Hints:

Selecting the appropriate Charge elements XPath expression might look something like this:

CODE --> XPath

//TabChargeDocument/Charge[OffenseID/ID = 'PENDING'] 
Typed, not tested. Your actual input document probably has more XML namespaces than you have shown. If so, you will have to add the namespace alias references to the various XPath elements.

The appropriate technique to use when copying a subtree from the input document to the output document is an identity transform. Using an identity transform, you can then add specific templates to override the copying. In this case you would like to rename a specific element. You can find an example here.

Tom Morrison
Hill Country Software

RE: How do I output all charges with with Pending ID?

Taking on Tom Morrison's indications:

CODE --> XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:output method="xml"/>

  <xsl:template match="TabChargeDocument">
    <xsl:copy>
      <xsl:apply-templates select="Charge[OffenseID/ID = 'PENDING']"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="Charge[OffenseID/ID = 'PENDING']">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="OffenseCite">
    <xsl:element name="StatuteNumber">
      <xsl:copy-of select="text()"/>
    </xsl:element>
  </xsl:template>
  
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet> 

RE: How do I output all charges with with Pending ID?

Close, but...

I would suggest a template that matches "/" and from there do an apply-templates that selects "//TabChargeDocument/Charge[OffenseID/ID = 'PENDING']". This will intercept the natural progression of the built-in rules and 'skip over' the SOAP <envelope> and <body> elements. If you don't do this, the combination of the identity transform and built-in rules will recurse through them, and copy them to the output document.

I also prefer an apply-templates within or at the end of each template that matches the special elements. This may not be necessary in these particular cases (where the elements appear to be leaf nodes in the input tree), but in general you have to restart the recursion down the document tree.

Tom Morrison
Hill Country Software

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close