[ 
http://issues.apache.org/jira/browse/XALANJ-2180?page=comments#action_12375174 
] 

dcaveney commented on XALANJ-2180:
----------------------------------

This issue only appears when I try to sort a nodeset within an applet. Using 
the same programming logic and stylesheets from within a console application 
works as expected:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import java.io.*;
import org.xml.sax.*;
import javax.xml.parsers.*;

public class ControlPanel {
  public static void main(String[] args) {
    String strDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<root/> \n" ;

    String strStyle =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<stylesheet \n" +
"   xmlns=\"http://www.w3.org/1999/XSL/Transform\"; \n" +
"   xmlns:xalan=\"http://xml.apache.org/xalan\"; \n" +
"   xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"; version=\"1.0\">\n" +
"  <output method=\"text\"/>\n" +
"\n" +
"  <template match=\"/\">\n" +
"    <variable name=\"foo\">\n" +
"      <xsl:element name=\"bar\">\n" +
"        <xsl:attribute name=\"priority\">1</xsl:attribute>\n" +
"        <text>Priority = 1</text>\n" +
"      </xsl:element>\n" +
"      <xsl:element name=\"bar\">\n" +
"        <xsl:attribute name=\"priority\">2</xsl:attribute>\n" +
"        <text>Priority = 2</text>\n" +
"      </xsl:element>\n" +
"    </variable>\n" +
"    <for-each select=\"xalan:nodeset($foo)/xsl:bar\">\n" +
"      <xsl:sort data-type=\"number\" order=\"descending\" 
select=\"@priority\"/>\n" +
"      <value-of select=\"text()\"/>\n" +
"    </for-each>\n" +
"  </template>\n" +
"</stylesheet>\n";

    System.out.println(strDoc);
    System.out.println(strStyle);

    try {

      DocumentBuilderFactory docBuilderFactory = (DocumentBuilderFactory) new 
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl();

      docBuilderFactory.setIgnoringComments(false);
      docBuilderFactory.setIgnoringElementContentWhitespace(false);
      docBuilderFactory.setCoalescing(false);
      docBuilderFactory.setExpandEntityReferences(true);
      docBuilderFactory.setValidating(false);
      docBuilderFactory.setNamespaceAware(true);
      DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();

      StringReader sourceReader = new StringReader(strDoc);
      StringReader styleReader = new StringReader(strStyle);
      InputSource sourceInput = new InputSource(sourceReader);
      InputSource styleInput = new InputSource(styleReader);
      Document sourceDoc = builder.parse(sourceInput);
      Document styleDoc = builder.parse(styleInput);
      DOMSource sourceDOM = new DOMSource(sourceDoc);
      DOMSource styleDOM = new DOMSource(styleDoc);

      TransformerFactory transformerFactory = new 
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl();
      Templates templates = transformerFactory.newTemplates(styleDOM);
      Transformer transformer = (Transformer) templates.newTransformer();

      StringWriter resultWriter = new StringWriter();
      StreamResult resultStream = new StreamResult(resultWriter);
      transformer.transform(sourceDOM, resultStream);
      String tranResult = resultWriter.toString();
      System.out.println(tranResult);

    } catch (Exception e) {
      System.out.println(e.toString());
    }

  }
}

Produces the following output:

Priority = 2Priority = 1


> xsl:sort does not work with nodeset variables
> ---------------------------------------------
>
>          Key: XALANJ-2180
>          URL: http://issues.apache.org/jira/browse/XALANJ-2180
>      Project: XalanJ2
>         Type: Bug

>   Components: Xalan
>     Versions: 2.6
>  Environment: Java Plug-in 1.5.0_04 creates DocumentBuilderFactory, 
> TransformerFactory, Transformer objects etc. using newInstance() methods.
>     Reporter: dcaveney
>  Attachments: Scenario.zip, sortbug.xsl
>
> The symptoms I'm seeing are the same as in issue #Xalanj-860 but I can't use 
> the same workaround. A template creates some elements within a variable, and 
> then tries to sort the resulting nodeset. The following example produces no 
> output:
> <?xml version="1.0" encoding="UTF-8"?>
> <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform"; 
> xmlns:xalan="http://xml.apache.org/xalan"; 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
>   <output method="text"/>
>   <template match="/">
>     <variable name="foo">
>       <xsl:element name="bar">
>          <xsl:attribute name="priority">1</xsl:attribute>
>         <text>Priority = 1</text>
>       </xsl:element>
>       <xsl:element name="bar">
>         <xsl:attribute name="priority">2</xsl:attribute>
>         <text>Priority = 2</text>
>       </xsl:element>
>     </variable>
>     <for-each select="xalan:nodeset($foo)/xsl:bar">
>       <xsl:sort data-type="number" order="descending" select="@priority"/>
>       <value-of select="text()"/>
>     </for-each>
>   </template>
> </stylesheet>

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to