Project

Profile

Help

Support #2087

closed

Selecting an attribute with a namespace qualifier doesn't work in an XSL

Added by Andrew Seales almost 10 years ago. Updated almost 10 years ago.

Status:
Rejected
Priority:
Normal
Category:
XPath conformance
Sprint/Milestone:
-
Start date:
2014-06-11
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

If you have an XML document such as:

<root xmlna:ns="http://namespace">
  <a ns:attr="value">
</root>

and an XSL that does:

<xsl:stylesheet [...] xmlns:ns="http://namespace">
  <xsl:value-of select="/root/a/@ns:attr" />
</xsl:stylesheet>

The value that is output is blank.

If the XSL is changed to @/root/a/attr@(so no namespace) then the correct value is output.

Shouldn't the XPath select require the namespace on the attribute?


Files

saxontext.zip (3.99 KB) saxontext.zip Andrew Seales, 2014-06-13 14:53
Actions #1

Updated by O'Neil Delpratt almost 10 years ago

Hi,

The namespace declaration in the source document looks incorrect. Should it not be xmlns:ns="http://namespace" instead of what you have quoted above.

With that change the transformation works for me as expected.

Kind regards,

O'Neil

Actions #2

Updated by Andrew Seales almost 10 years ago

Sorry that's just a typo in the bug report. The namespaces on the actual document I'm working with are correct.

Actions #3

Updated by Andrew Seales almost 10 years ago

Sorry that's just a typo in the bug report. The namespaces on the actual document I'm working with are correct.

I also tested my actual documents using XSLSpy 2014 to do the transformation to eliminate typos, and this worked as expected.

Actions #4

Updated by O'Neil Delpratt almost 10 years ago

Hi, I am still getting the expected output from the commandline and from oxygen 16 which uses Saxon 9.5.1-5.

Please may you send me your stylesheet and xml source document either on this bug issue or privately which ever you prefer. Also please can you detail how you run Saxon and the edition used. The more details will help me to reproduce the problem you have described.

Thanks and kind regards,

O'Neil

Actions #5

Updated by Andrew Seales almost 10 years ago

Attached is a ZIP with a simple Java class, and the XML documents that show the error.

I'm using Java 1.8.0.05 and Maven 3.0.5. I'm running the test from within Eclipse(Spring Tool Suite v 3.5.1) on 64-bit Ubuntu 14.04.

The test program prints the results of the two transformations. The first result runs the XSL with the XPath that has no namespace on the selector, yet it still gets the data from an attribute with the namespace.

The second result runs the XSL with the XPath that uses the namespace on the selelector, but it does not get the data from the attribute.

Eg, the file "namespace.xsl" should be the one that works, but it does not.

Actions #6

Updated by Andrew Seales almost 10 years ago

Forgot to mention, using Saxon-HE 9.5.1-5.

Actions #7

Updated by O'Neil Delpratt almost 10 years ago

Hi, it still works for me, but I am using Java 7. The only thing is I have not test the code on Java 8, which I will do next. Maybe there is something strange happening using Java 8.

I ran your stylesheet from the command line and from a modified version of Java program which you supplied. May you can try it, please see the code below:

import javax.xml.transform.stream.StreamSource;

import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;


public class App {
    public static void main(String[] args) throws Exception {

        System.out.println("XML with no namespace on attribute(should not have value attribute, but does):\n");
        transform("./input.xml", "./no_namespace.xsl");

        System.out.println("\n\nXML with namespace on attribute(should have value attribute, but does not):\n");
        transform("./input.xml", "./namespace.xsl");
    }

    private static void transform(String xmlFileName, String xslFileName) throws Exception {



        Processor processor = new Processor(false);

        XsltExecutable executable = processor.newXsltCompiler().compile(new StreamSource(xslFileName));
        XsltTransformer transformer = executable.load();

        Serializer serializer = processor.newSerializer(System.out);
        transformer.setDestination(serializer);
        transformer.setSource(new StreamSource(xmlFileName));

        transformer.transform();
}

Here is my output:

XML with no namespace on attribute(should not have value attribute, but does):

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns="http://namespace"/>


XML with namespace on attribute(should have value attribute, but does not):

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns="http://namespace">value</test>
Actions #8

Updated by Andrew Seales almost 10 years ago

I tried both the Java 8 VM and Java 7 VM(both Oracle VMs, not OpenJDK). The output from my program under both JVMs is the same:

XML with no namespace on attribute(should not have value attribute, but does):

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns="http://namespace">value</test>


XML with namespace on attribute(should have value attribute, but does not):

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns="http://namespace"/>

I also tried this from the command line to rule out anything weird Eclipse might be doing and I get the same result.

If I don't have the Saxon JAR on the classpath, then no stylesheet transformation happens, and the output is the text of the stylesheet.

If I try your program, then the output is what I expect, and it is the same as your output:

XML with no namespace on attribute(should not have value attribute, but does):

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns="http://namespace"/>


XML with namespace on attribute(should have value attribute, but does not):

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns="http://namespace">value</test>

Does this mean I'm using the standard API incorrectly? Perhaps I'm missing a configuration parameter?

Actions #9

Updated by O'Neil Delpratt almost 10 years ago

It does seem like you have some incorrect configuration or setup. Please may you paste in to this bug issue or email me what you have typed in on the command line.

In terms of the Java program. The program you sent just seems to print out the stylesheets for me. It is much better and easier for you to use Saxon's s9api as given in the code I sent you. There are lots of samples for s9api and the documentation on the API is fairly comprehensive.

Actions #10

Updated by Andrew Seales almost 10 years ago

Command line I used for my code:

$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

$ java  -classpath target/classes/:$HOME/.m2/repository/net/sf/saxon/Saxon-HE/9.5.1-5/Saxon-HE-9.5.1-5.jar edina.test.saxontest.App
XML with no namespace on attribute(should not have value attribute, but does):

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns="http://namespace">value</test>


XML with namespace on attribute(should have value attribute, but does not):

<?xml version="1.0" encoding="UTF-8"?>
<test xmlns:ns="http://namespace"/>

The code I send was just test code rather than what I'm using in my application. But I should be able to replace it with the direct Saxon9 API rather than use the generic Java API.

Actions #11

Updated by O'Neil Delpratt almost 10 years ago

  • Tracker changed from Bug to Support
  • Status changed from New to Rejected
  • Assignee set to O'Neil Delpratt

It looks like the setup in your code was causing the issue.

You should have no more issues by using the code I sent you. If it is ok with you I will close this bug issue.

Please register to edit this issue

Also available in: Atom PDF