Robert Papp created XALANJ-2602:
-----------------------------------

             Summary: Selected attribute is not iterated correctly
                 Key: XALANJ-2602
                 URL: https://issues.apache.org/jira/browse/XALANJ-2602
             Project: XalanJ2
          Issue Type: Bug
      Security Level: No security risk; visible to anyone (Ordinary problems in 
Xalan projects.  Anybody can view the issue.)
          Components: transformation, XPath, XSLTC
    Affects Versions: 2.7.2, 2.7.1
         Environment: Android 5 and Windows 10 x64
            Reporter: Robert Papp
            Assignee: Steven J. Hathaway


{code:title=items.xml}
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<?xml-stylesheet type="text/xsl" href="items.xslt"?>
<root>
  <item name="Item 1">
    <item name="Item 2">
      <item name="Item 3">
        <item name="Item 4" />
      </item>
    </item>
  </item>
</root>
{code}

The context where the problem occurs is "Item 4"'s element node.

{code:title=items.xslt}
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
        <xsl:output method="html" encoding="utf-8" />
        <xsl:template match="//item[@name='Item 4']">
                <p>ancestor::item<ul>
                <xsl:for-each select="ancestor::item">
                        <li>
                                <xsl:value-of select="position()" />
                                /
                                <xsl:value-of select="last()" />
                                :
                                <xsl:value-of select="@name" />
                        </li>
                </xsl:for-each>
                </ul></p>

                <p>ancestor::item/@name<ul>
                <xsl:for-each select="ancestor::item/@name">
                        <li>
                                <xsl:value-of select="position()" />
                                /
                                <xsl:value-of select="last()" />
                                :
                                <xsl:value-of select="." />
                        </li>
                </xsl:for-each>
                </ul></p>
        </xsl:template>
</xsl:stylesheet>
{code}

If the parents of the context node are selected, everything is ok, but if the 
{{@name}}s of each parent is selected, then the iteration stops abruptly 
without error.

{code:title=Expected output (sans HTML)}
ancestor::item
1 / 3 : Item 1
2 / 3 : Item 2
3 / 3 : Item 3

ancestor::item/@name
1 / 3 : Item 1
2 / 3 : Item 2
3 / 3 : Item 3
{code}

{code:title=Actual output (sans HTML)}
ancestor::item
1 / 3 : Item 1
2 / 3 : Item 2
3 / 3 : Item 3

ancestor::item/@name
1 / 3 : Item 1
{code}

I tried Java 5 and 8 built-in processor, Chrome 52 and Internet Explorer 11; 
they all agree that the second iterations should result in 3 items. Originally 
I found the issue while running a similar XPath query foreach in Android 5.0 on 
a Galaxy S5, which uses Xalan 2.7.1; on my Windows 10 machine I ran the 
processing with Xalan 2.7.2 on the classpath:
{code}
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class Solution {
        public static void main(String[] args) throws IOException, 
TransformerException {
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer(new 
StreamSource(new FileInputStream("items.xslt")));
                StringWriter capture = new StringWriter();
                transformer.transform(new StreamSource(new 
FileInputStream("items.xml")), new StreamResult(capture));
                System.out.println(capture.toString());
        }
}
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@xalan.apache.org
For additional commands, e-mail: dev-h...@xalan.apache.org

Reply via email to