M
Mark Space
Here's a problem that's driving me nuts.
The program below executes correctly as is. There's one line in the xsl
string commented out. If you uncomment that line, the output changes.
It adds the line "I can't jump." That's the value of the <jump> tag.
But I don't ask for this tag to be put in the output anywhere in the xsl
file, so I don't understand why it's appearing in the output.
Can anyone shed some illumination on this conundrum?
package xslweirdness;
import java.io.StringReader;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
private final static String xml = "<?xml version=\"1.0\"?>\n"
+" <monkey>\n"
+" <boy can=\"no\">\n"
+" <jump>I can't jump.</jump>\n"
+" </boy>\n"
+" </monkey>";
private final static String xsl = "<xsl:stylesheet "
+"xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" "
+"version=\"1.0\">\n"
+" <xslutput method=\"html\"/>"
+" <xsl:template match=\"/monkey\" >\n"
+" Jumping: <xsl:value-of select=\"boy/@can\" />\n"
// +" <xsl:apply-templates/>"
+" </xsl:template>\n"
+"</xsl:stylesheet>";
public static void main(String[] args) throws Exception {
System.out.println( "XML:--------------------\n" + xml );
System.out.println( "XSL:--------------------\n" + xsl );
StreamSource xslSrc = new StreamSource( new StringReader(xsl) );
TransformerFactory tf = TransformerFactory.newInstance();
Transformer xfrm = tf.newTransformer(xslSrc);
StreamResult stmOut = new StreamResult( System.out );
StreamSource xmlSrc = new StreamSource( new StringReader(xml) );
System.out.println( "transform:--------------------\n" );
xfrm.transform(xmlSrc, stmOut);
}
}
The program below executes correctly as is. There's one line in the xsl
string commented out. If you uncomment that line, the output changes.
It adds the line "I can't jump." That's the value of the <jump> tag.
But I don't ask for this tag to be put in the output anywhere in the xsl
file, so I don't understand why it's appearing in the output.
Can anyone shed some illumination on this conundrum?
package xslweirdness;
import java.io.StringReader;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
private final static String xml = "<?xml version=\"1.0\"?>\n"
+" <monkey>\n"
+" <boy can=\"no\">\n"
+" <jump>I can't jump.</jump>\n"
+" </boy>\n"
+" </monkey>";
private final static String xsl = "<xsl:stylesheet "
+"xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" "
+"version=\"1.0\">\n"
+" <xslutput method=\"html\"/>"
+" <xsl:template match=\"/monkey\" >\n"
+" Jumping: <xsl:value-of select=\"boy/@can\" />\n"
// +" <xsl:apply-templates/>"
+" </xsl:template>\n"
+"</xsl:stylesheet>";
public static void main(String[] args) throws Exception {
System.out.println( "XML:--------------------\n" + xml );
System.out.println( "XSL:--------------------\n" + xsl );
StreamSource xslSrc = new StreamSource( new StringReader(xsl) );
TransformerFactory tf = TransformerFactory.newInstance();
Transformer xfrm = tf.newTransformer(xslSrc);
StreamResult stmOut = new StreamResult( System.out );
StreamSource xmlSrc = new StreamSource( new StringReader(xml) );
System.out.println( "transform:--------------------\n" );
xfrm.transform(xmlSrc, stmOut);
}
}