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 June 3rd, 2015, 04:10 PM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How do I display CommercialVehicleFlag?

Here is my sample xml document with 2 Charges. Each Charge has a child element (Vehicle) which has the CommercialVehicleFlag.
Sometimes a xml document may have under Integration, a Citation which will have
CommercialVehicleFlag (xpath) /Integration/Citation/CommercialVehicleFlag).
or for this particular xml document
/Integration/Charge/Vehicle/CommercialVehicleFlag.

For that reason I need to check CommercialVehicleFlag from tow different places (xpaths) so as to display them based on where they are located. Either under Citation or under Charge.

Desired output
Code:
<Charge ID="10905889">
		<Vehicle>
			<CommercialVehicleFlag>false</CommercialVehicleFlag>
		</Vehicle>
	</Charge>
	<Charge ID="10905890">
		<Vehicle>
			<CommercialVehicleFlag>true</CommercialVehicleFlag>
		</Vehicle>
	</Charge>
My sample xml document
Code:
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="DL Notice to DVS" MessageID="67084403" xmlns="">
	<Case Op="E" InternalID="1617090273" ID="12124494" xmlns:user="http://tylertechnologies.com">
		<Charge ID="10905889">
			<Vehicle>
				<CommercialVehicleFlag>false</CommercialVehicleFlag>
			</Vehicle>
		</Charge>
		<Charge ID="10905890">
			<Vehicle>
				<CommercialVehicleFlag>true</CommercialVehicleFlag>
			</Vehicle>
		</Charge>
	</Case>
</Integration>
My xsl line of code which is returning false for both

Code:
<xsl:value-of select="(/Integration/Citation/Vehicle[CommercialVehicleFlag]|/Integration/Case/Charge/Vehicle[CommercialVehicleFlag])[1]/CommercialVehicleFlag"/>
 
Old June 3rd, 2015, 04:32 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Breaking up your expression:

<xsl:value-of select="

(/Integration/Citation/Vehicle[CommercialVehicleFlag]

this part selects nothing because there is no Citation element

|/Integration/Case/Charge/Vehicle[CommercialVehicleFlag])

this part selects both Vehicle elements in your source

[1]

this selects the first of the two Vehicle elements

/CommercialVehicleFlag"/>

this selects the CommercialVehicleFlag child of the first Vehicle element, which has the value "false".
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Data Will Not Display When I Click On Display Button sprdave BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 12 February 13th, 2011 12:09 AM
display annumol Hibernate 1 March 21st, 2008 03:43 PM
Display javaLös Java GUI 5 May 12th, 2005 12:29 PM
can't display syounger JSP Basics 3 February 12th, 2004 07:46 AM
display an image gorney .NET Web Services 0 December 29th, 2003 01:52 PM





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