----- Original Message -----
Sent: Thursday, October 04, 2001 12:10 PM
Subject: contribute new function in XSL taglib

Dear Sir:
I had developed a new function about using XSL stylesheet  and a stylesheet parameter
to transform XML documents into another document type (XML, HTML, or other). 
 
I'd made XSL taglib some abilities to use stylesheet's parameters by making a additonal attribute named "params"
for Apply custom tag to get a collection stylesheet parameters and the relatives program segment is as following:
 
    /**
     * The Iterator of XSL-styesheet's parameters ArrayList.
     */
    private Iterator iterator = null;
 
    public void setParams(Collection parameters) {
      if(parameters.size() > 0)
         iterator = parameters.iterator();
    }
 
I also modified the transformation process in ApplyTag.java for that property, the new transformation process
program segment by using additonal stylesheet's parameters is as following:
 
 // Create an XSLT processor and use it to perform the transformation
 XSLTProcessor processor = null;
 try {
     processor = XSLTProcessorFactory.getProcessor();
            // Set a parameter value that the stylesheet can obtain.
            if(iterator != null) {
               while(iterator.hasNext()) {
                     String[] param = (String[]) iterator.next();
                     // param[0]=parameter's name, param[1]=value type, param[2]=value
                     // Set a param named in "param[0]", that the stylesheet can obtain.
                     processor.setStylesheetParam(param[0], processor.createXString(param[2]));
               } // While
            } // If
     processor.process(data, style, result);
 } catch (SAXException e) {
     throw new JspException(e.toString());
 }
 
I rewrote the xsl.tld file and defined some properties about new "params" attribute as follow:
 
    <attribute>
      <name>params</name>
      <required>false</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
 
Also I wrote some test files for this new XSL taglib and it works fine.
 
All the new ApplyTag.java, cltInvoice.xsl, cltOrder.xml and cltXslParams.jsp files are appended with this email.
 
your sincerely
     Chung-Lin Teng    email:[EMAIL PROTECTED]
 
 

cltXslParams.jsp

<?xml version="1.0"?>
<Order>
   <Date>2001-10-10</Date>
   <Reference>CLT168</Reference>
   <Buyer>
      <Name>Emason eBooks</Name>
      <Address>
         <Street>my Test Buyer's street</Street>
         <Country>US</Country>
      </Address>
   </Buyer>
   <Seller>
      <Name>CLT</Name>
      <Address>
         <Street>my Test Seller's street</Street>
         <Country>US</Country>
      </Address>
   </Seller>
   <Lines>
      <Product>
         <Description>EZ Study JSP/XML/XSL by Taglibs</Description>
         <Quantity>5</Quantity>
         <Price>19.99</Price>
         <Total>549.95</Total>
      </Product>
      <Product>
         <Description>CLT XML Solutions</Description>
         <Quantity>10</Quantity>
         <Price>44.00</Price>
         <Total>440.00</Total>
      </Product>
   </Lines>
   <Total>989.95</Total>
</Order>
  
<?xml version="1.0"?>

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

<xsl:output method="xml"/>

<xsl:param name="id"/>
<xsl:param name="date"/>
<xsl:param name="due"/>
<xsl:template match="/Order">
<Invoice>
   <Reference><xsl:value-of select="$id"/></Reference>
   <YourReference><xsl:value-of
      select="Reference"/></YourReference>
   <Date><xsl:value-of select="$date"/></Date>
   <Due><xsl:value-of select="$due"/> days</Due>
   <Terms>Please make your check payable to CLT.</Terms>
   <Seller>
      <Name>CLT</Name>
      <Address>
         <Street>my Test Seller's street</Street>
         <Locality>dream</Locality>
         <PostalCode>12345</PostalCode>
         <Region>IN</Region>
         <Country>US</Country>
      </Address>
   </Seller>
   <Buyer>
      <Name><xsl:value-of select="Buyer/Name"/></Name>
      <Address>
         <Street><xsl:value-of select="Buyer/Address/Street"/></Street>
         <Country><xsl:value-of select="Buyer/Address/Country"/></Country>
      </Address>
   </Buyer>
   <Lines>
      <xsl:for-each select="Lines/Product">
         <Product>
            <Description><xsl:value-of
               select="Description"/></Description>
            <Quantity><xsl:value-of
               select="Quantity"/></Quantity>
            <Price><xsl:value-of
               select="Price"/></Price>
            <Total><xsl:value-of
               select="Total"/></Total>
         </Product>
      </xsl:for-each>
   </Lines>
   <Total><xsl:value-of select="Total"/></Total>
</Invoice>
</xsl:template>

</xsl:stylesheet>

ApplyTag.java

Reply via email to