Create dynamic checklistbox using xsl

When we use database we design Item table like following:

ID Name Description Price Per Unit Batter Topping Quantity
0001 Cake Chocolate Cake 0.55 Regular Maple 100
0002 Cake Blueberry Cake 0.55 Blueberry Maple 200
0003 Raised Raised Glazed 0.55 Regular Glazed 150
0004 Buttermilk Chocolate Buttermilk 1.55 Chocolate   180
0005 Bar Chocolate Bar 0.75 Regular Maple 100

The XML file structure looks like this:

<?xml version=”1.0″ encoding=”utf-8″?>
   <Item>
        <ID><![CDATA[0001]]></ID>
        <Name>Cake</Name>
        <Description><![CDATA[Chocolate Cake]]></Description>
        <PricePerUnit>0.55</PricePerUnit>
        <Batter>Regular</Batter>
        <Topping><![CDATA[Maple]]></Topping>
        <Quantity>100</Quantity>
   </Item>
   <Item>
        <ID><![CDATA[0002]]></ID>
        <Name>Cake</Name>
        <Description><![CDATA[Blueberry Cake]]></Description>
        <PricePerUnit>0.55</PricePerUnit>
        <Batter>Blueberry</Batter>
        <Topping><![CDATA[Maple]]></Topping>
        <Quantity>200</Quantity>
   </Item>
   <Item>
        <ID><![CDATA[0003]]></ID>
        <Name>Raised</Name>
        <Description><![CDATA[Raised Glazed]]></Description>
        <PricePerUnit>0.55</PricePerUnit>
        <Batter>Regular</Batter>
        <Topping><![CDATA[Glazed]]></Topping>
        <Quantity>150</Quantity>
   </Item>
   <Item>
        <ID><![CDATA[0004]]></ID>
        <Name>Buttermilk</Name>
        <Description><![CDATA[Chocolate Buttermilk]]></Description>
        <PricePerUnit>1.55</PricePerUnit>
        <Batter>Chocolate</Batter>
        <Topping><![CDATA[]]></Topping>
        <Quantity>180</Quantity>
   </Item>
   <Item>
        <ID><![CDATA[0005]]></ID>
        <Name>Bar</Name>
        <Description><![CDATA[Chocolate Bar]]></Description>
        <PricePerUnit>0.75</PricePerUnit>
        <Batter>Regular</Batter>
        <Topping><![CDATA[Maple]]></Topping>
        <Quantity>100</Quantity>
   </Item>

In XSL file we have a CkecklistBox. We need to fetch all Item name from the Items.xml file. The default file for OptDialog.xsl file is OptDialog.xml file. We have to add two templates to display checklistbox with item names.

<xsl:key name=”XmlItem” match=”Identification” use=”Name”/>
  <xsl:variable name=”itemnames” select=”document(‘Items.xml’)” />
 <!– collect all catalog names for checklistbox –>
  <xsl:template match=”itemnames/Item/Name” name=”XmlItemref”>
    <xsl:variable name=”ItemName”>
 <!– fetch all item name and store into ItemName variable–>
    <xsl:variable name=”elemName” select=”$itemnames/Item/Name”/>
    <xsl:for-each select=”$elemName”>
      <xsl:value-of select=”.”/>,
    </xsl:for-each>
    </xsl:variable>
 <!– add checklistbox for display item name–>
    <div style=”background-color:white;height:200px;width:100px;font-family:Verdana; font-size:8pt;float:left;overflow-y:scroll;overflow-x:visible;position:relative;” name=”lstItemNames” id=”lstItemNames” OnClick=”JavaScript:getItemName();”>
      <xsl:attribute name=”scope”><![CDATA[report]]></xsl:attribute>
      <xsl:attribute name=”xpath”><![CDATA[//Item/Name]]></xsl:attribute>
  <!– call item-tokenize template to split items–>
      <xsl:call-template name=”item-tokenize”>
        <xsl:with-param name=”list” select=”$ItemName” />
        <xsl:with-param name=”delimiter” select=”‘,'”/>
      </xsl:call-template>
    </div>
  </xsl:template>

The item-tokenize tamplate:

<!– split string tokenizer Template –>
  <xsl:template name=”item-tokenize”>
    <xsl:param name=”list” />
    <xsl:param name=”delimiter” />
    <xsl:variable name=”newlist”>
      <xsl:choose>
        <xsl:when test=”contains($list, $delimiter)”>
          <xsl:value-of select=”normalize-space($list)” />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select=”concat( normalize-space($list), $delimiter )”/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name=”first” select=”substring-before($newlist, $delimiter)” />
    <xsl:variable name=”remaining” select=”substring-after($newlist, $delimiter)” />
    <xsl:element name=”newitem”>
      <INPUT NAME=”chkOptions” TYPE=”CHECKBOX”>
        <xsl:attribute name=’value’>
          <xsl:value-of select=”$first”/>
        </xsl:attribute>
      </INPUT>
      <xsl:value-of select=”$first”/>
    </xsl:element>
    <xsl:if test=”$remaining”>
      <xsl:call-template name=”item-tokenize”>
        <xsl:with-param name=”list” select=”$remaining” />
        <xsl:with-param name=”delimiter”>
          <xsl:value-of select=”$delimiter”/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

Now call the template into table to display the checklistbox:

<TABLE width=100%border=0cellpadding=5style=font-family:Verdana; font-size:8pt>

<TR>

<TD colspan=2“>

<xsl:call-template name=XmlItemref>

</xsl:call-template>

</TD>

</TR>

</TABLE>

The output is given below:

Advertisements

World Wide Web Consortium(W3C)

The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web (abbreviated WWW or W3). It is arranged as a consortium where member organizations maintain full-time staff for the purpose of working together in the development of standards for the W3. As of February 2008, the W3C had 434 members.

W3C also engages in education and outreach, develops software and serves as an open forum for discussion about the Web. It was founded and is headed by Sir Tim Berners-Lee.

History:

The World Wide Web Consortium (W3C) was founded by Tim Berners-Lee after he left the European Organization for Nuclear Research (CERN) in October, 1994. It was founded at the Massachusetts Institute of Technology Laboratory for Computer Science (MIT/LCS) with support from the DARPA — which had pioneered the Internet — and the European Commission.

W3C was created to ensure compatibility and agreement among industry members in the adoption of new standards. Prior to its creation, incompatible versions of HTML were offered by different vendors, increasing the potential for inconsistency between web pages. The consortium was created to get all those vendors to agree on a set of core principles and components which would be supported by everyone.

It was originally intended that CERN host the European branch of W3C; however, CERN wished to focus on particle physics, not information technology. In April 1995 the Institut national de recherche en informatique et en automatique (INRIA) became the European host of W3C, with Keio University becoming the Japanese branch in September 1996. Starting in 1997, W3C created regional offices around the world; as of October 2007 it has sixteen World Offices covering Australia, the Benelux countries (the Netherlands, Luxemburg, and Belgium), China, Finland, Germany and Austria, Greece, Hungary, India, Ireland, Israel, Italy, Japan, South Korea, Korea, Morocco, South Africa, Spain, Sweden, and the United Kingdom.

In January 2003, the European host was transferred from INRIA to the European Research Consortium for Informatics and Mathematics (ERCIM), an organization that represents European national computer science laboratories.

The Consortium is jointly administered by the MIT Computer Science and Artificial Intelligence Laboratory (CSAIL) in the USA, the European Research Consortium for Informatics and Mathematics (ERCIM) (in Sophia Antipolis, France), and Keio University (in Japan). The W3C also has World Offices in sixteen regions around the world. The W3C Offices work with their regional Web communities to promote W3C technologies in local languages, broaden W3C’s geographical base, and encourage international participation in W3C Activities.

Standards

W3C/IETF Standards (over Internet protocol suite):

W3C Sites is a collection of web sites created by designers that conform with the W3C standards. For more… W3C Sites.