xsl-list
[Top] [All Lists]

[xsl] Collect all the truncated fields in an array

2010-10-05 18:40:55
Team,

Thank you for helping. It worked. Now I want to extend the functionality. I 
changed the subject appropriately..

XSL: 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="InputXml">
<xsl:variable name="MAX_InputXmlValue1">1</xsl:variable>
<xsl:variable name="MAX_InputXmlValue2">2</xsl:variable>
<xsl:variable name="MAX_InputXmlValue3">3</xsl:variable>
<OutputXml>   
<xsl:choose>
<xsl:when test="InputXmlValue3='' and InputXmlValue2=''">
    <outputTempVar1></outputTempVar1>
    <outputVar1><xsl:value-of 
select="substring(InputXmlValue1,1,$MAX_InputXmlValue1)"/></outputVar1>
    <outputVar2></outputVar2>
</xsl:when>
<xsl:when test="InputXmlValue3=''">
    <outputTempVar1></outputTempVar1>
    <outputVar1><xsl:value-of 
select="substring(InputXmlValue1,1,$MAX_InputXmlValue1)"/></outputVar1>
    <outputVar2><xsl:value-of 
select="substring(InputXmlValue2,1,$MAX_InputXmlValue2)"/></outputVar2>
</xsl:when>
<xsl:otherwise>
    <outputTempVar1><xsl:value-of 
select="substring($InputXmlValue1,1,$MAX_InputXmlValue1)InputXmlValue1"/></outputTempVar1>

    <outputVar1><xsl:value-of 
select="substring(InputXmlValue2,1,$MAX_InputXmlValue2)"/></outputVar1>
    <outputVar2><xsl:value-of 
select="substring(InputXmlValue3,1,$MAX_InputXmlValue3)"/></outputVar2>
</xsl:otherwise>
</xsl:choose>
</OutputXml>
</xsl:template>
</xsl:stylesheet>    

In the above xsl, I am taking 3 input values and using the below logic, mapped 
to 3 output values. During the mapping, I introduced truncation logic.
Now I need to collect all the input values that got truncated at the end of the 
program in the form of string array. Ultimate goal is that
I need to frame an email collecting all truncated values. 

Conditions:
1. If all the 3 input variables 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.   


eg: If I send the following input xml
INPUT:  
<?xml version="1.0" encoding="UTF-8"?>
<InputXml>    
    <InputXmlValue1>12</InputXmlValue1>
    <InputXmlValue2>345</InputXmlValue2>
    <InputXmlValue3>678</InputXmlValue3>
</InputXml>

Based on the above xsl, output will be
OUTPUT:
<?xml version="1.0" encoding="UTF-8"?>
<OutputXml>    
    <outputTempVar1>1</outputTempVar1>  ==> Truncated. "12" got truncated to "1"
    <outputVar1>34</outputVar1>    ==> Truncated. "345" got truncated to "34"
    <outputVar2>678</outputVar2>
</OutputXml>

What I want is: 
<?xml version="1.0" encoding="UTF-8"?>
<OutputXml>    
    <outputTempVar1>1</outputTempVar1>  ==> Truncated. "12" got truncated to "1"
    <outputVar1>34</outputVar1>    ==> Truncated. "345" got truncated to "34"
    <outputVar2>678</outputVar2>
    <TruncatedValues>'[InputXmlValue1: Initial[12], 
Truncated[1]],[InputXmlValue2: Initial[345], Truncated[34]]</TruncatedValues>
</OutputXml>

Is this possible?



----- Original Message ----
From: sudheshna iyer <sudheshnaiyer(_at_)yahoo(_dot_)com>
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Sent: Tue, October 5, 2010 11:18:45 AM
Subject: Re: [xsl] Variable value change based on condition

Thank you all. Let me try this. 



--- 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, 10:51 AM
On 05/10/2010 15:38, sudheshna iyer
wrote:
Team, thank you for your patience. I complete
understand that converting java code to xslt doesn't make
much sense. But tech change required this, which I don't
have control on. Since I came from java background, it is
becoming harder for me..

so there were no variables at all, you meant "elements" I
doubt anyone would have guessed that.


<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="InputXml">
<OutputXml>    
<xsl:choose>
<xsl:when test="InputXmlValue3='' and
InputXmlValue2=''">
   
<outputTempVar1></outputTempVar1>
    <outputVar1><xsl:value-of
select="InputXmlValue1"/></outputVar1>
    <outputVar2></outputVar2>
</xsl:when>
<xsl:when test="InputXmlValue3=''">
   
<outputTempVar1></outputTempVar1>
    <outputVar1><xsl:value-of
select="InputXmlValue1"/></outputVar1>
    <outputVar2><xsl:value-of
select="InputXmlValue2"/></outputVar2>
</xsl:when>
<xsl:otherwise>
    <outputTempVar1><xsl:value-of
select="InputXmlValue1"/></outputTempVar1>
    <outputVar1><xsl:value-of
select="InputXmlValue2"/></outputVar1>
    <outputVar2><xsl:value-of
select="InputXmlValue3"/></outputVar2>
</xsl:otherwise>
</xsl:choose>
</OutputXml>
</xsl:template>
</xsl:stylesheet>


________________________________________________________________________
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>
--~--


      

--~------------------------------------------------------------------
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>
--~--