Hello Chris,

Try putting xalan-2.4.0.jar in JAVA_HOME/jre/lib/endorsed.  Make sure
you stop all java processes before doing this.  Then restart Tomcat.

Jake

Tuesday, November 12, 2002, 10:43:29 AM, you wrote:

CH> I've got a strange problem with tomcat transforming an xml document with 
CH> xsl apparently only on Linux. Below is a small portion of the style 
CH> sheet that is relevant:

CH>     <xsl:template match="/">
CH>         <xsl:apply-templates/>
CH>     </xsl:template>

CH>    <xsl:template match="grammar:rule">
CH>         <!--Make sure this is capital-->
CH>         <xsl:if test="string(parent::node()/@root) != string(./@id)">
CH>             <xsl:value-of select="translate(substring(@id, 1, 1), 
CH> 'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/><xsl:value-of 
CH> select="translate(substring(@id, 2), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
CH> 'abcdefghijklmnopqrstuvwxyz')"/>
CH>         </xsl:if>
CH>         (
CH>             <xsl:apply-templates/>
CH>         )
CH>     </xsl:template>

CH>     <xsl:template match="grammar:one-of">  
CH>         <xsl:variable name="weights">
CH>             <xsl:value-of select="sum(grammar:item/@weight)"/>
CH>         </xsl:variable>
CH>         [<xsl:for-each select="grammar:item"><xsl:choose>
CH>             <xsl:when test="@repeat='0-1'"><xsl:text> 
CH> </xsl:text>?<xsl:apply-templates/><xsl:if 
CH> test="string(@weight)!=''">~<xsl:value-of select="concat('0.', 
CH> string(round((number(@weight) div 
CH> number($weights))*10)))"/></xsl:if><xsl:text> </xsl:text></xsl:when>
CH>             <xsl:when test="@repeat='0+'">
CH>                 <xsl:text> </xsl:text>*(<xsl:apply-templates/>)<xsl:if 
CH> test="string(@weight)!=''">~<xsl:value-of select="concat('0.', 
CH> string(round((number(@weight) div 
CH> number($weights))*10)))"/></xsl:if><xsl:text> </xsl:text>
CH>             </xsl:when>
CH>             <xsl:when test="@repeat='1+'">
CH>                 <xsl:text> </xsl:text>+(<xsl:apply-templates/>)<xsl:if 
CH> test="string(@weight)!=''">~<xsl:value-of select="concat('0.', 
CH> string(round((number(@weight) div 
CH> number($weights))*10)))"/></xsl:if><xsl:text> </xsl:text>
CH>             </xsl:when>
CH>             <xsl:otherwise>(<xsl:apply-templates/>)<xsl:if 
CH> test="string(@weight)!=''">~<xsl:value-of select="concat('0.', 
CH> string(round((number(@weight) div 
CH> number($weights))*10)))"/></xsl:if><xsl:text> </xsl:text></xsl:otherwise>
CH>         </xsl:choose></xsl:for-each>]
CH>     </xsl:template>

CH>     <xsl:template match="grammar:item">
CH>         <xsl:choose>
CH>             <xsl:when test="@repeat='0-1'"><xsl:text> 
CH> </xsl:text>?<xsl:apply-templates/><xsl:if 
CH> test="string(@repeat-prob)!=''">~<xsl:value-of 
CH> select="@repeat-prob"/></xsl:if><xsl:text> </xsl:text></xsl:when>
CH>             <xsl:when test="@repeat='0+'">
CH>                 <xsl:text> </xsl:text>*(<xsl:apply-templates/>)<xsl:if 
CH> test="string(@repeat-prob)!=''">~<xsl:value-of 
CH> select="@repeat-prob"/></xsl:if><xsl:text> </xsl:text>
CH>             </xsl:when>
CH>             <xsl:when test="@repeat='1+'">
CH>                 <xsl:text> </xsl:text>+(<xsl:apply-templates/>)<xsl:if 
CH> test="string(@repeat-prob)!=''">~<xsl:value-of 
CH> select="@repeat-prob"/></xsl:if><xsl:text> </xsl:text>
CH>             </xsl:when>
CH>             <xsl:otherwise>(<xsl:apply-templates/>)<xsl:if 
CH> test="string(@repeat-prob)!=''">~<xsl:value-of 
CH> select="@repeat-prob"/></xsl:if><xsl:text> </xsl:text></xsl:otherwise>
CH>         </xsl:choose>
CH>     </xsl:template>

CH>     <xsl:template match="grammar:tag">
CH>        <xsl:choose>
CH>            <xsl:when test="starts-with(string(text()),'Append')"></xsl:when>
CH>            <xsl:otherwise>{<xsl:value-of select="'&lt;'" 
CH> disable-output-escaping="yes"/><xsl:value-of 
CH> select="substring-before(text(),'=')"/><xsl:text> 
CH> "</xsl:text><xsl:value-of 
CH> select="substring-before(substring-after(text(),'=&quot;'), 
'&quot;')"/>><xsl:text>"</xsl:text><xsl:value-of select="'&gt;'" 
CH> disable-output-escaping="yes"/>}</xsl:otherwise>
CH>        </xsl:choose>
CH>     </xsl:template>

CH>     <xsl:template match="grammar:item/text()"><xsl:value-of 
CH> select="normalize-space(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
CH> 'abcdefghijklmnopqrstuvwxyz'))"/></xsl:template>
CH>     <xsl:template match="*|@*|text()" priority="-1">
CH>         <xsl:copy>
CH>             <xsl:copy-of select="@*"/>
CH>             <xsl:apply-templates/>
CH>         </xsl:copy>
CH>     </xsl:template>  
CH> </xsl:stylesheet>

CH> Below is a subset of the xml I'm parsing:
CH>         <field name="browse_subject" expr="/'default/'">
CH>             <grammar version="1.0" 
CH> xmlns="http://www.w3.org/2001/06/grammar"; root="subject_grammar" 
CH> type="application/grammar+xml">
CH>                 <rule id="subject_grammarOpening">
CH>                     <one-of>
CH>                         <item>
CH>                             Do this for me
CH>                         </item>
CH>                         <item>
CH>                             I want
CH>                         </item>
CH>                         <item>
CH>                             Give me
CH>                         </item>
CH>                         <item>
CH>                             I demand
CH>                         </item>
CH>                         <item>
CH>                             I'd like
CH>                         </item>
CH>                         <item>
CH>                             I would like
CH>                         </item>
CH>                     </one-of>
CH>                 </rule>
CH>                 <rule id="subject_grammarSelection" scope="public">
                    
CH> <one-of><item>default<tag>browse_subject="default"</tag></item></one-of>
CH>                 </rule>
CH>                 <rule id="subject_grammarClosing">
CH>                     <one-of>
CH>                         <item>
CH>                             now
CH>                         </item>
CH>                         <item>
CH>                             please
CH>                         </item>
CH>                         <item>
CH>                             that's all
CH>                         </item>
CH>                         <item>
CH>                             right now
CH>                         </item>
CH>                     </one-of>
CH>                 </rule>
CH>                 <rule id="subject_grammar" scope="public">
CH>                     <item repeat="0-1">
CH>                         <ruleref uri="#subject_grammarOpening"/>
CH>                     </item>
CH>                     <ruleref uri="#subject_grammarSelection"/>
CH>                     <item repeat="0-1">
CH>                         <ruleref uri="#subject_grammarClosing"/>
CH>                     </item>
CH>                 </rule>
CH>                 <rule id="subject_grammarOpening">
CH>                     <one-of>
CH>                         <item>
CH>                             Do this for me
CH>                         </item>
CH>                         <item>
CH>                             I want
CH>                         </item>
CH>                         <item>
CH>                             Give me
CH>                         </item>
CH>                         <item>
CH>                             I demand
CH>                         </item>
CH>                         <item>
CH>                             I'd like
CH>                         </item>
CH>                         <item>
CH>                             I would like
CH>                         </item>
CH>                     </one-of>
CH>                 </rule>
CH>                 <rule id="subject_grammarSelection" scope="public">
                    
CH> <one-of><item>default<tag>browse_subject="default"</tag></item></one-of>
CH>                 </rule>
CH>                 <rule id="subject_grammarClosing">
CH>                     <one-of>
CH>                         <item>
CH>                             now
CH>                         </item>
CH>                         <item>
CH>                             please
CH>                         </item>
CH>                         <item>
CH>                             that's all
CH>                         </item>
CH>                         <item>
CH>                             right now
CH>                         </item>
CH>                     </one-of>
CH>                 </rule>
CH>             </grammar>
CH> </field>


CH> I've repeated the rule id="subject_grammarClosing" to show off the 
CH> problem tomcat is having with parsing this.

CH> below is the correct transform that occurs from the commmand line with 
CH> jdk 1.3.1+, from standalone applications with jdk 1.3.1+ and from the 
CH> Windows version of tomcat 4.0.4 with jdk 1.4.1. I'm using xalan 
CH> 2.1.0+(I've tried several) and xerces 2.2.1. This is the correct output:

CH>     <field name="browse_subject" expr="/'default/'">
CH>             <grammar type="application/x-gsl"><![CDATA[
CH>                 Subject_grammaropening
CH>         (
           
                   
CH>         [(do this for me) (i want) (give me) (i demand) (i'd like) (i 
CH> would like) ]
   
               
CH>         )
CH>     Subject_grammarselection
CH>         (
           
                   
CH>         [(default{<browse_subject "default">}) ]
   
               
CH>         )
CH>     Subject_grammarclosing
CH>         (
           
                   
CH>         [(now) (please) (that's all) (right now) ]
   
               
CH>         )
   
CH>         (
           
CH>                      ?Subject_grammaropening
CH>                     Subject_grammarselection
CH>                      ?Subject_grammarclosing
               
CH>         )
CH>     Subject_grammaropening
CH>         (
           
                   
CH>         [(do this for me) (i want) (give me) (i demand) (i'd like) (i 
CH> would like) ]
   
               
CH>         )
CH>     Subject_grammarselection
CH>         (
           
                   
CH>         [(default{<browse_subject "default">}) ]
   
               
CH>         )
CH>     Subject_grammarclosing
CH>         (
           
                   
CH>         [(now) (please) (that's all) (right now) ]
   
               
CH>         )
   
CH>             ]]></grammar></field>

CH> This is the problem result when running the transformation in tomcat 
CH> under linux with jdk 1.3.1 and jdk1.4.1, both blackdown and sun, and 
CH> Tomcat 3.3.1 to Tomcat 4.0.6.

CH> <field name="browse_subject" expr="/'default/'">                        
CH>     <grammar type="application/x-gsl"><![CDATA[
CH>                 Subject_grammaropening
CH>         (
                                                
CH>         [(do this for me) (i want) (give me) (i demand) (i'd like) (i would like) 
]>}) ]
                                
CH>         )
CH>     Subject_grammarclosing
CH>         (
                                                
CH>         [(now) (please) (that's all) (right now) ]
                                
CH>         )
    
CH>         (
CH>                                                  ?Subject_grammaropening           
                             Subject_grammarselection                                  
      
CH> ?Subject_grammarclosing                                
CH>         )
CH>     Subject_grammaropening
CH>         (
                                                
CH>         [(do this for me) (i want) (give me) (i demand) (i'd like) (i would like) ]
                                
CH>         )
CH>     Subject_grammarselection
CH>         (
                                                
CH>         [(default{<browse_subject default>}) ]
                                
CH>         )
CH>     Subject_grammarclosing
CH>         (
                                                
CH>         [(now) (please) (that's all) (right now) ]
                                
CH>         )
    
CH>             ]]></grammar></field>


CH> As you can see these extra characters ">}) ]" are printed on 
Subject_grammarOpening line and the next element Subject_grammarSelection is ignored 
only for the first instance of the elements. The
CH> repeated. second set of elements work fine.

CH> In a series of these field/grammar elements, there is a repeating 
CH> pattern where the first element with one-of child elements will fail to 
CH> see the closing tag and start into the next sibling element. This cannot 
CH> be a bug in xerces or xalan, because the standalone apps work fine. I'm 
CH> familar with the problems with making sure the correct parser is being 
CH> read into the classpath in tomcat and can assure you I've replace each 
CH> instance of the installed xerces with multiple different versions, 
CH> renaming them aaaxerces just to make sure they're picked up first. This 
CH> cannot be a bug in java linux because the standalone applications work 
CH> fine, I've also done the transformation inside of netbeans and jbuilder. 
CH> The only piece left is tomcat. The windows version of tomcat 4.0.4 works 
CH> fine for both jdk 1.3.1 and jdk1.4. Only different tomcat versions on 
CH> linux have this problem. Below is code from  the test servlet I wrote.

CH>    protected void processRequest(HttpServletRequest request, 
CH> HttpServletResponse response)
CH>     throws ServletException, IOException {
CH> try
CH> {
CH>         if(request.getParameter("inputType")!=null &&
CH>    request.getParameter("outputType")!=null &&
CH>    request.getParameter("withTemplate")!=null && 
CH> request.getParameter("inputSource")!=null)
CH> {
CH>         String inputUrl = request.getParameter("inputSource");
CH>     javax.xml.transform.Transformer transformer = null;
CH>     javax.xml.transform.Source inputSource = null;
CH>     if(request.getParameter("inputType").equals("stringReader"))
CH>     {

CH>             BufferedReader in = new BufferedReader(new 
CH> FileReader(inputUrl));
CH>             StringBuffer sb = new StringBuffer();
CH>             String str;
CH>             while ((str = in.readLine()) != null) {
CH>                 sb.append(str);
CH>             }
CH>             in.close();



CH>                 inputSource = new  
CH> javax.xml.transform.stream.StreamSource(new StringReader(sb.toString()));
CH>     }
CH>     else
CH>     {
CH>         inputSource = new javax.xml.transform.sax.SAXSource(new 
CH> org.xml.sax.InputSource(new java.io.FileInputStream(inputUrl)));
CH>     }

CH>     if(request.getParameter("withTemplate").equals("testWithTemplate"))
CH>     {
CH>             javax.xml.transform.TransformerFactory tFactory =
CH>                   javax.xml.transform.TransformerFactory.newInstance();
CH>     javax.xml.transform.Templates template = tFactory.newTemplates(new 
CH> javax.xml.transform.sax.SAXSource(new org.xml.sax.InputSource(
CH> new java.io.FileInputStream(request.getParameter("templateSource")))));
CH>         transformer = template.newTransformer();
CH>     }
CH>     else
CH>     {
CH>         // 1. Instantiate a TransformerFactory.
CH>         javax.xml.transform.TransformerFactory tFactory =
CH>                   javax.xml.transform.TransformerFactory.newInstance();

CH>         // 2. Use the TransformerFactory to process the stylesheet 
CH> Source and
CH>         //    generate a Transformer.
CH>         transformer = tFactory.newTransformer(new 
CH> javax.xml.transform.sax.SAXSource(new org.xml.sax.InputSource(new 
CH> java.io.FileInputStream(request.getParameter("templateSource")))));

CH>     }


CH>     if(request.getParameter("outputType").equals("printWriter"))
CH>     {
CH>                 response.setContentType("text/xml");
CH>         PrintWriter out = response.getWriter();
CH>                 transformer.transform(inputSource, new 
CH> javax.xml.transform.stream.StreamResult(out));
CH>                 out.close();
CH>     }
CH>     else
CH>     {
CH>                 transformer.transform(inputSource, new 
CH> javax.xml.transform.stream.StreamResult(new 
CH> java.io.FileWriter(request.getParameter("outputfile"))));
CH>         response.setContentType("text/html");
CH>                 java.io.PrintWriter out = response.getWriter();
CH>                 out.println("<html><head></head><body><a "+
                
CH> "href=\"file://"+request.getParameter("outputfile")+"\">test "+
CH>                 "results</a></body></html>");
CH>     }
CH> }
CH> else
CH> {
CH> response.setContentType("text/html");
CH> java.io.PrintWriter out = response.getWriter();
CH> out.println("<html><head></head><body><form action=\"test\">input "+
CH> "type:<select name=\"inputType\"><option value=\"stringReader\">String "+
CH> "Reader Test</option> "+
CH> "<option value=\"fileReader\">File Reader Test</option> "+
CH> "</select>&nbsp;&nbsp;with template?<select name=\"withTemplate\"><option "+
CH> "value=\"testWithTemplate\">With Template</option><option "+
CH> "value=\"testWithoutTemplate\">No Template "+
CH> "Test</option></select>&nbsp;&nbsp;output type:<select "+
CH> "name=\"outputType\"><option value=\"tfileWriter\">File Writer "+
CH> "Test</option><option value=\"printWriter\">Print Writer "+
CH> "Test</option></select>&nbsp;&nbsp;input source: <input type=\"text\" 
CH> name=\"inputSource\" size=\"40\"/>&nbsp;&nbsp;xsl source<input 
CH> type=\"text\" name=\"templateSource\" 
size=\"40\"/>>&nbsp;&nbsp;optional(if using file writer)&nbsp;output 
CH> file<input type=\"text\" name=\"outputfile\" size=\"40\"/><input 
CH> type=\"submit\" name=\"submit\" "+
"value=\"submit\"/>></form></body></html>");
CH> }

CH> }
CH> catch(Throwable t)
CH> {
CH>     t.printStackTrace();
CH> }

CH>     }


CH> Does anyone have any ideas what is going on inside of tomcat that would 
CH> cause this kind of odd transformation? If anyone is willing to assist I 
CH> can share the test webapp alone with a sample stylesheet and a sample 
CH> xml document.

CH> Thanks,
CH> Chris Hazen
CH> [EMAIL PROTECTED]
CH> 913-234-8075





CH> --
CH> To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@;jakarta.apache.org>
CH> For additional commands, e-mail: <mailto:tomcat-user-help@;jakarta.apache.org>



-- 
Best regards,
 Jacob                            mailto:hoju@;visi.com


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@;jakarta.apache.org>

Reply via email to