You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/08/08 14:30:04 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler Copy.java

morten      01/08/08 05:30:04

  Modified:    java/src/org/apache/xalan/xsltc/compiler Copy.java
  Log:
  Fix for use of attribute sets with the xsl:copy element. We were a bit too
  restrictive in our tests to see if it was safe to send the attributes to
  the output handler. We only compiled in a test to see if the copied node
  was an elment, but should also have tested if the xsl:copy element's
  parent node was a LRE or a xsl:element element.
  PR:		bugzilla 2538
  Obtained from:	n/a
  Submitted by:	morten@apache.org
  Reviewed by:	morten@apache.org
  
  Revision  Changes    Path
  1.5       +29 -13    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Copy.java
  
  Index: Copy.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Copy.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Copy.java	2001/08/08 10:57:05	1.4
  +++ Copy.java	2001/08/08 12:30:03	1.5
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Copy.java,v 1.4 2001/08/08 10:57:05 morten Exp $
  + * @(#)$Id: Copy.java,v 1.5 2001/08/08 12:30:03 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -115,6 +115,7 @@
   					Util.getJCRefType("I"),
   					il.getEnd());
   
  +	// Get the name of the node to copy and save for later
   	il.append(methodGen.loadDOM());
   	il.append(methodGen.loadCurrentNode());
   	il.append(methodGen.loadHandler());
  @@ -128,27 +129,42 @@
   	il.append(DUP);
   	il.append(new ASTORE(name.getIndex()));
   	final BranchHandle ifBlock1 = il.append(new IFNULL(null));
  +
  +	// Get the length of the node name and save for later
   	il.append(new ALOAD(name.getIndex()));
   	final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
   	il.append(new INVOKEVIRTUAL(lengthMethod));
  -	// save length for later tests
   	il.append(new ISTORE(length.getIndex()));
  -	// only if use-attribute-sets specified compile this seq
  +
  +	// Copy in attribute sets if specified
   	if (_useSets != null) {
  -	    // check if element; if not skip to translate body
  -	    il.append(new ILOAD(length.getIndex()));
  -	    final BranchHandle ifBlock2 = il.append(new IFEQ(null));
  -	    // length != 0 -> element -> do attribute sets
  -	    _useSets.translate(classGen, methodGen);
  -	    // not an element; root
  -	    ifBlock2.setTarget(il.append(NOP));
  +	    // If the parent of this element will result in an element being
  +	    // output then we know that it is safe to copy out the attributes
  +	    final SyntaxTreeNode parent = getParent();
  +	    if ((parent instanceof LiteralElement) ||
  +		(parent instanceof LiteralElement)) {
  +		_useSets.translate(classGen, methodGen);
  +	    }
  +	    // If not we have to check to see if the copy will result in an
  +	    // element being output.
  +	    else {
  +		// check if element; if not skip to translate body
  +		il.append(new ILOAD(length.getIndex()));
  +		final BranchHandle ifBlock2 = il.append(new IFEQ(null));
  +		// length != 0 -> element -> do attribute sets
  +		_useSets.translate(classGen, methodGen);
  +		// not an element; root
  +		ifBlock2.setTarget(il.append(NOP));
  +	    }
   	}
  -	// instantiate body of xsl:copy
  +
  +	// Instantiate body of xsl:copy
   	translateContents(classGen, methodGen);
  -	// check if element
  +
  +	// Call the output handler's endElement() if we copied an element
  +	// (The DOM.shallowCopy() method calls startElement().)
   	il.append(new ILOAD(length.getIndex()));
   	final BranchHandle ifBlock3 = il.append(new IFEQ(null));
  -	// emit endElement
   	il.append(methodGen.loadHandler());
   	il.append(new ALOAD(name.getIndex()));
   	il.append(methodGen.endElement());
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org