Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 21st, 2016, 03:28 PM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How do I output all child elements for Charge node for each Charge?

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 will be output as
StatuteNumber
Code:
<StatuteNumber>169A.20.1(5)</StatuteNumber>

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

Code:
<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>
<b>Input xml doc</b>

Code:
<?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>
 
Old September 21st, 2016, 04:46 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

You can use
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    
    <xsl:param name="id" as="xs:string" select="'PENDING'"/>
    
    <xsl:output indent="yes"/>
    
    <xsl:template match="/">
        <xsl:apply-templates select="//Charge[OffenseID/ID = $id]"></xsl:apply-templates>
    </xsl:template>
    
    <xsl:template match="Charge">
        <xsl:copy>
            <ReportingAgency>
                <xsl:value-of select="Report/ReportingAgencyORI/ID"/>
            </ReportingAgency>
            <Statute>
                <StatuteDescription>
                    <xsl:value-of select="OffenseDescriptionText"/>
                </StatuteDescription>
                <StatuteNumber>
                    <xsl:value-of select="OffenceCite"/>
                </StatuteNumber>
            </Statute>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
which at least shows how to select certain "Charge" elements.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT logic for repeating child elements within parent node Srinibondugula BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 5 November 8th, 2011 12:05 PM
how to find child node when there is mentioned (child::*) mlohokare XSLT 3 May 12th, 2009 12:40 PM
Accessing a node bases on child node value musman0047 XSLT 1 February 27th, 2009 12:26 PM
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
Child Node Output Neal XSLT 0 June 7th, 2006 03:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.