RE: [xsl] Conditional selecting

Subject: RE: [xsl] Conditional selecting
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 13 Dec 2004 19:51:41 -0000
No directly relevant to your question, but in XSLT 1.0 this:

			<!-- number() makes sure we process field_no as a
number and not a string, otherwise 11 comes before 9 ;) -->
			<xsl:sort select="number(field_no)"
order="ascending"/>

doesn't do what the comment says. In 1.0 you get a string-based sort unless
you specify data-type="number", regardless whether the actual values are
numeric.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Jim Neff [mailto:jneff@xxxxxxxxxxxxxxx] 
> Sent: 13 December 2004 17:21
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Conditional selecting
> 
> Greetings,
> 
> Here is my XML document:
> 
> 	<record type="EA0">
> 		<field_no>46</field_no>
> 		<starting_position>267</starting_position>
> 		<length>8</length>
> 		<justification>L</justification>
> 		<content></content>
> 		<default_value></default_value>
> 		<data_type>text</data_type>
> 	</record>
> 	<record type="EA0">
> 		<field_no>47</field_no>
> 		<starting_position>275</starting_position>
> 		<length>8</length>
> 		<justification>L</justification>
> 		<content>CLM_CR_DT</content>
> 		<default_value></default_value>
> 		<data_type>date2</data_type>
> 	</record>
> 	<record>
> 		<record type="EA0">
> 		<field_no>47</field_no>
> 		<plan_id>CHNCT</plan_id>
> 		<starting_position>275</starting_position>
> 		<length>8</length>
> 		<justification>L</justification>
> 		<content>claim_paid_date</content>
> 		<default_value></default_value>
> 		<data_type>date2</data_type>
> 	</record>	
> 	<record type="EA0">
> 		<field_no>48</field_no>
> 		<starting_position>283</starting_position>
> 		<length>1</length>
> 		<justification>L</justification>
> 		<content></content>
> 		<default_value></default_value>
> 		<data_type>text</data_type>
> 	</record>
> 
> 
> Here is a snip of the XSL stylesheet that uses this :
> 
> 	<xsl:apply-templates select="$field_definitions/*[@type 
> = 'EA0']">
> 		
> 			<!-- number() makes sure we process 
> field_no as a
> number and not a string, otherwise 11 comes before 9 ;) -->
> 			<xsl:sort select="number(field_no)"
> order="ascending"/>
> 		
> 			<xsl:with-param name="current_context" 
> select="."/>
> 						
> 	</xsl:apply-templates>
> 
> 
> I select those records that match the "EA0" record type and 
> then sort them
> according to field_no.  
> 
> My question is in regards to field_no 47.  What I want to do 
> is select the
> record IF there is a plan_id instead of the record without a 
> plan id.  Not
> all records will have a plan id.  
> 
> So if there is a child element of the record node that has a 
> value in the
> plan_id field then use that record number instead of the 
> record with the
> same number that DOES NOT have the plan_id.
> 
> 
> Thanks in advance,
> Jim Neff

Current Thread