Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 17th, 2009, 12:58 AM
Authorized User
 
Join Date: Jul 2009
Posts: 25
Thanks: 1
Thanked 0 Times in 0 Posts
Default implement in XSLT

Hi ,

Can someone help me to implement this logic in xslt

I have an incoming xml from which i need to display output xml according to the input xml indicators
Following is the condition table according to which i need to display the output in runtime
Ind ColorInd code1 code2 code3
0 NA TA 10 15
99 NA TA ED 15
1 (N=0 or more) TB 10 15
1 (R>=1 and N>=0)
TB N5 AB
1 (Y=1 and N>=0) TB O2 15
1 (R>=1,Y>=1 N>=0) TB OG AB
1 (Y>1 and N>=0) TB OG 15


Where In input xml When colorInd=0 it is N
=1 it is Y
=2 it is R

InputXML

<Users>

<User>

<Color>

<Ind>1</Ind>
<ColorInd>1</ColorInd>

</color>
<Color>

<Ind>1</Ind>
<ColorInd>2</ColorInd>

</color>
.....
</User>
</Users>

OutputXML:

<Color>

<Code1>TB</Code1>
<Code2>N5</Code2>
<Code3>15</Code2>
<Color/>

I need to display the code1,code2,code3 dynamicaly based on the input xml
For example if (R>=1 and N>=0) i.e when R occurs one or more times and N occurs 0 or more times in input xml . i need to display TB N5 AB

Thanks in advance
 
Old November 17th, 2009, 01:10 AM
Authorized User
 
Join Date: Jul 2009
Posts: 25
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Code:
Ind                 ColorInd                              code1    code2    code3
0                   NA                                       TA       10        15
99                  NA                                      TA        ED         15
1                    (N=0 or more)                         TB         10          15
1                          (R>=1 and N>=0)               TB        N5         AB
1                        (Y=1  and N>=0)                   TB         O2         15
1                                 (R>=1,Y>=1 N>=0)          TB       OG        AB
1                                        (Y>1 and N>=0)     TB        OG        15
 
Old November 17th, 2009, 06:18 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Looks to me as if you could translate your decision table directly into a set of template rules, one for each row of the table. For example, the fourth row might become

Code:
<xsl:template match="Color[Ind='1' and ColorInd='2']">
  <Color>
        <Code1>TB</Code1>
        <Code2>N5</Code2>
        <Code3>AB</Code2>
   </Color>
</xsl:template>
However, I haven't understood the RNY part of your problem description, I don't understand the mapping from ColorInd to RNY values.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old November 17th, 2009, 09:10 AM
Authorized User
 
Join Date: Jul 2009
Posts: 25
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks kay,the above proposed solution doesnt work for me.sorry for not being clear.I will try to explain again

R,N,Y values are determined from the input XML by the value of colorInd.

when colorInd=0 It is N
=1 It is Y
=2 It is R

And in decision table in ColorInd column where you see (Eg: R>=1,N>=0,Y=1 and N>=0) are all different conditions to display those code1,code2,code3 values.

so in order to validate those different coditions and display dynamically according to those conditions first i need to determine the count of R's count of N's and count of Y's in the input XML.If the Ind=1 ,Once i determine the occurences of these RNY values i need to apply the different conditions and display corresponding values

For example if (R>=1 and N>=0) i.e when R occurs one or more times and N occurs 0 or more times in input xml . i need to display TB N5 AB


Input XML
Code:
<Users>

<User>
<Ind>1</Ind>

<Color>
..
<ColorInd>1</ColorInd>

</Color> 
<Color>
..
<ColorInd>2</ColorInd>

</Color> 
.....
<!-- Color node can occur n times-->
</User>
</Users>
sorry i posted the wrong xml in my previous post "placed Ind at wrong level"

so If Ind is "0" or "99" i can directly display corresponding code1,2,3 values and need not to verify any conditions

Let me know if iam not clear.

Thanks a lot
 
Old November 17th, 2009, 09:52 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

So, it seems that by R>=1 you actually mean

[code]
count(//ColorInd[.=0]) >= 1
[code]

So your logic becomes

Code:
<xsl:choose>
  <xsl:when test="Ind=0">
    ...
  </
  <xsl:when test="Ind=1">
      <xsl:choose>
           <xsl:when test="count(//ColorInd[.=2]) >= 1 and count(//ColorInd[.=0]) >= 0">
               <color>
                   <code1>TB</code1>
                   <code2>10</code2>
                   <code3>15</code3>
                </color>
           </xsl:when>
           <xsl:when test="count(//ColorInd[.=0]) >= 1">
               <color>
                   <code1>TB</code1>
                   <code2>10</code2>
                   <code3>15</code3>
                </color>
           </xsl:when>
etc.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old November 18th, 2009, 01:44 AM
Authorized User
 
Join Date: Jul 2009
Posts: 25
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks a lot Kay,that helped me





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to implement AJAX Maxxim ASP.NET 2.0 Professional 2 October 22nd, 2007 01:35 PM
Not able to implement the given logic in my XSLT ashyabhi_hp XSLT 2 January 27th, 2006 07:24 AM
how to implement this?please help? Desmond Classic ASP Databases 1 May 27th, 2005 11:06 PM
Cannot implement or extend Rusk Apache Tomcat 1 June 16th, 2004 06:29 AM
how can i best implement a many to many relation? Haroldd Access 1 July 2nd, 2003 03:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.