[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: returning nodes (not a string) using variable-choo

Subject: RE: returning nodes (not a string) using variable-choose.
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 24 Jun 2006 08:45:22 +0100
xsl not condition
If you need a variable that contains a node-set in 1.0, where the
computation involves a conditional, the best approach is generally

<xsl:variable name="ns" select="XXX[condition] | YYY[not(condition)]"/>

which selects XXX if condition is true, or YYY if condition is false. It
involves evaluating the condition twice, but you can do that in advance and
put the result in a boolean variable, so it becomes:

<xsl:variable name="condition" select="$type='Other'"/>
<xsl:variable name="ns" select="XXX[$condition] | YYY[not($condition)]"/>

Remember that xsl:value-of always flattens its input to a string (actually a
text node, but it amounts to the same thing).

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

> -----Original Message-----
> From: Steve [mailto:subsume@xxxxxxxxx] 
> Sent: 23 June 2006 20:06
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  returning nodes (not a string) using variable-choose.
> 
> The below somewhat elaborate lines assign a value to 
> $typeInfo, however they don't return results as a nodelist, 
> just a big string.
> ------
> 
> <xsl:variable name="typeInfo">
> 	<xsl:choose>
> 		<xsl:when test="$type='Other'">
> 			<xsl:value-of select="$desc" />
> 		</xsl:when>
> 		<xsl:otherwise>
> 			<xsl:variable name="table">
> 				<xsl:choose>
> 					<xsl:when 
> test="$type='Organizational Contact'">
> 						
> <xsl:text>CA_Orgs</xsl:text>
> 					</xsl:when>
> 					<xsl:when 
> test="$type='Meeting or Training'">
> 						
> <xsl:text>CA_Meetings</xsl:text>
> 					</xsl:when>
> 					<xsl:when test="$type='Travel'">
> 						
> <xsl:text>CA_Travel</xsl:text>
> 					</xsl:when>
> 				</xsl:choose>
> 			</xsl:variable>
> 			<xsl:value-of
> select="document(concat(concat(concat('http://server.org/getXM
> L.asp?key=id&amp;val=',$desc),'&amp;table='),$table))"
> />
> 		</xsl:otherwise>
> 	</xsl:choose>
> </xsl:variable>
> <xsl:value-of select="$typeInfo" />
> -----------------
> 
> Anyway to do this with XSLT 1.0 or am I pushing it?
> 
> --Steve

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.