xsl-list
[Top] [All Lists]

Re: [xsl] Variable value change based on condition

2010-10-05 08:56:02
Thank you .
Input variables are nothing but the elements of input xml. I have java program 
which I have to convert to xslt. 
 
I need to copy these input variables(elements of input xml) to output variables 
based on some condition.

Conditions:
1. If all the 3 input variables(elements of input xml) are present (element 
present with no blanks), map /InputXmlValue1 -> outputTempVar1, map 
/InputXmlValue2 -> outputVar1 and map /InputXmlValue3 -> outputVar2.
2. If there are only two input variables present (/InputXmlValue1, 
/InputXmlValue2), map /InputXmlValue1 -> outputVar1 and map /InputXmlValue2 -> 
outputVar2.
3. If there is only one input variable is present (//InputXmlValue1), map 
/InputXmlValue1 -> outputVar1.   

So output variables get their values based on input variable's presence 
(element being present and not empty). I am trying to transform one xml to 
another. So input variables come from input xml.
/InputXmlValue1 , /InputXmlValue2, /InputXmlValue3 are the values of the 
elemnents in the incoming xml
====


--- On Tue, 10/5/10, David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk> wrote:

From: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
Subject: Re: [xsl] Variable value change based on condition
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: "sudheshna iyer" <sudheshnaiyer(_at_)yahoo(_dot_)com>
Date: Tuesday, October 5, 2010, 9:09 AM
On 05/10/2010 13:59, sudheshna iyer
wrote:
Can this be achieved in xslt 1.0?



You just repeated your initial question.

XSLt doesn't have "inout variables" and "output variables"
I'm guessing that you mean, respectively, parameters and
variables, but it's hard to be sure.

variables always have a value if declared so you need to
say what value you want for each of your three variables.

I'm guessing that you want, for variable3 something like
the first of input3,input2,input1 that is not empty.

In XSLT2 that would be

<xsl:variable name="variable3"
select="($var3,$var2,$var1)[not(.='')][1]"/>

on xslt1 if you could use



<xsl:variable name="variable3" >
<xsl:choose>
<xsl:when test=not($var3='')"><xsl:value-of
select="$var3"/></xsl:when>
<xsl:when test=not($var2='')"><xsl:value-of
select="$var2"/></xsl:when>
<xsl:otherwise><xsl:value-of
select="$var1"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>


David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered
in England
and Wales with company number 1249803. The registered
office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United
Kingdom.

This e-mail has been scanned for all viruses by Star. The
service is
powered by MessageLabs.
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




      

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--