Pages

XSLT Custom Scripting Functoid - Dictionary Approach Repeating Record

Thursday, August 18, 2011
Q:

I have a Repeating record Where it contains id and description i need to select  based on  the value of description and pass on value of id and description both of them
sample xml :
<applicablerecords>
  <id>10</id>
  <description>3months</description>
  <id>12</id>
  <description>6months</description>
   <id>20</id>
  <description>24months</description>
   <id>35</id>
  <description>18months</description>
   <id>45</id>
  <description>24months</description>
</applicablerecords>

SOl:

Use the following Custom Xslt on a scripting functoid or you can also use c# script to createa dictionry and copy all the elements in to it and then search into it


xslt approach:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
         <xsl:for-each select="applicablerecords[description='24months']">
             <xsl:if test= "position()=1">
               <xsl:value-of select="id"/></td>
               <xsl:value-of select="description"/></td>
             <xsl:if>
           </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>





c# Approach:



public static string  populatevalues(string param1, string param2)
{
        system.collections.dictionary mydictionary = new system.collections.dictionary<String,string>;
        mydictionary.add(param1,param2);
}

use cumulative functoid to accumulate values thru records then

public static string  populatevalues(string param1, string param2)
{

        system.collections.dictionary mydictionary = new system.collections.dictionary<String,string>;
        if(mydictionary.containsvalue(param2))
               return mydictionary.id || mydictionary.description


}

No comments:

Post a Comment

Post Your Comment...