Altova Mailing List Archives


[xsl] Collect all the truncated fields in an array

From: sudheshna iyer <sudheshnaiyer@-----.--->
To: xsl-list@-----.------------.---
Date: 10/5/2010 11:41:00 PM
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@y...>
To: xsl-list@l...
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@n...> wrote:

> From: David Carlisle <davidc@n...>
> Subject: Re: [xsl] Variable value change based on condition
> To: xsl-list@l...
> Cc: "sudheshna iyer" <sudheshnaiyer@y...>
> 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@l...>
> --~--
> 
> 




--~------------------------------------------------------------------
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@l...>
--~--


      

--~------------------------------------------------------------------
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@l...>
--~--

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.