DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6074>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6074 mode not working with apply-templates Summary: mode not working with apply-templates Product: XalanJ2 Version: 2.2.x Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Major Priority: Other Component: org.apache.xalan.xsltc AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] I'm using xalan_j_2_2D14 along with the included Xerces; I'm using the XSLTC compiler following the provided sample very closely. My xslt stylesheet includes two apply-templates calls with different mode="string" calls. If I have the "mode" references present, the stylesheet fails completely with no matches for that apply-templates. If I remove the MODE references from the apply-templates calls and from one template then that template is matched and the rest works. I'll attach the short Java program, the style sheet, and the short XML sample being used. This has been considerably simplified from what I am working on in order to make whatever is going wrong more obvious. The element names have been changed to protect the innocent. :) Here is the Java program: import java.util.Properties; import java.io.FileOutputStream; import javax.xml.transform.Templates; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; // Import all of the exceptions we'll need to check for import java.io.IOException; import java.io.FileNotFoundException; import javax.xml.transform.TransformerException; public class xsltTest { public static void main(String[] args) throws TransformerException, FileNotFoundException { String key = "javax.xml.transform.TransformerFactory"; String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; Properties props = System.getProperties(); props.put(key, value); System.setProperties(props); String inputName = "AID_en."; // Common root part for XSL/HTM String xmlInputURI = "test.xml"; // Always the same XML source String xslInputURI = inputName + "xsl"; String htmlOutputURI = inputName + "htm"; TransformerFactory tFactory; Templates translet; // Instantiate the TransformerFactory and use it along with a StreamSource // XSL style sheet to create a translet as a Templates object try { tFactory = TransformerFactory.newInstance(); translet = tFactory.newTemplates(new StreamSource(xslInputURI)); // For each transformation, instantiate a new Transformer and perform // the transformation from a StreamSource to a StreamResult. Transformer transformer = translet.newTransformer(); transformer.transform(new StreamSource(xmlInputURI), new StreamResult(new FileOutputStream(htmlOutputURI))); } catch (Exception e) { e.printStackTrace(); } } } Here is the XML document (test.xml): <?xml version = "1.0" encoding = "UTF-8"?> <Tv> <Show id = "11" name = "Winnie the Pooh"> <Actor id = "5555" name = "Tigger"/> <Actor id = "2222" name = "Roo"/> <Actor id = "3333" name = "Winnie"/> </Show> <Show id = "09" name = "Tom and Jerry"> <Actor id = "2020" name = "Tom"/> <Actor id = "1010" name = "Jerry"/> </Show> <Show id = "23" name = "Unnamed Show Idea"> <!-- This Group contains no elements --> </Show> </Tv> Finally the stylesheet (AID_en.xsl): <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Document Title</title> </head> <body> <p> Number of actors: <xsl:value-of select="count(Tv/Show/Actor)"/> </p> <p> Number of shows with actors: <xsl:value-of select="count(Tv/Show[count(Actor) > 0]))"/> </p> <p> Number of shows with ZERO actors: <xsl:value-of select="count(Tv/Show[count(Actor) = 0]))"/> </p> <!-- The xsl:if statements work fine but the xsl:apply-templates fail --> <hr/> <xsl:if test="Tv[count(Show[count(Actor) > 0]) > 0]"> <h1>Shows that contain actors:</h1> <xsl:apply-templates select="Tv/Show[count(Actor) > 0]" mode="yes"/> </xsl:if> <hr/> <xsl:if test="Tv[count(Show[count(Actor) = 0]) > 0]"> <h2>Shows with no cast</h2> <xsl:apply-templates select="Tv/Show[count(Actor) = 0]" mode="no"/> </xsl:if> </body> </html> </xsl:template> <!-- end of root template --> <!-- ******************************************************************* ** SHOW template #1 (mode=yes) ******************************************************************* --> <xsl:template match="Show" mode="yes"> <p>Show: <xsl:value-of select="@id"/> -- <xsl:value-of select="@name"/> has the following actors: <xsl:apply-templates select="Actor"/> </p> </xsl:template> <!-- ******************************************************************* ** SHOW template #2 (MODE=no) ******************************************************************* --> <xsl:template match="Show" mode="no"> <p>Show: <xsl:value-of select="@id"/> -- <xsl:value-of select="@name"/> has no actors</p> </xsl:template> <!-- ******************************************************************* ** Actor listing template, invoked only from SHOW template #1 ******************************************************************* --> <xsl:template match="Actor"> <p> <xsl:text>Actor link: </xsl:text> <a href="http://localhost/servlet?name={@name}"> <xsl:value-of select="@name"/> </a> <xsl:value-of select="@id"/> </p> </xsl:template> </xsl:stylesheet> As written above, neither match="show" template is ever matched. If you remove the mode from one template and from the apply-templates calls, then that one template will work and will be matched. I'm using Sun's Java 1.3.1 under Win2k. This is being compiled and run from within Visual Cafe if that makes any difference.
