Here it is:

1) the test xsl

<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform";
  xmlns:xalan="http://xml.apache.org/xalan";
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
  xmlns:gen="com.acme.apps"
  xmlns:myext="com.acme.apps.XalanExtensionFunctionsTest"
  exclude-result-prefixes="xalan gen wsdl"
  extension-element-prefixes="myext">

  <output method="xml" encoding="UTF-8" version="1.0"
    media-type="text/xml" indent="yes" xalan:indent-amount="2" />

  <template match="/">
    <gen:report>
      <apply-templates />
    </gen:report>
  </template>

  <template match="wsdl:definitions">
    <gen:configuration>
      <!-- BUG: couldn't make it work here -->
      <copy-of select="xalan:checkEnvironment()" />
    </gen:configuration>
    <gen:test func="sayHello">
      <value-of select="myext:sayHello()" />
    </gen:test>
    <gen:test func="lookupNamespaceUri">
      <!-- PROBLEM: works for 'wsdl' prefix,
           for 'tns' and everything else,
           e.g. 'soap', 'xsd', etc., returns null
           -->
      <value-of select="myext:lookupNamespaceUri(current(), 'tns')" />
    </gen:test>
  </template>
</stylesheet>

2) the test xml can be found here: http://www.webservicex.net/ConvertTemperature.asmx?wsdl

3) the test:
package com.acme.apps;

import java.io.File;
import java.io.IOException;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import junit.framework.TestCase;

import org.w3c.dom.Node;

public final class XalanExtensionFunctionsTest
        extends TestCase {
    private static final String TEST_ROOT_DIR = "target/test-classes";

    private static final String TEST_XML =
        "com/acme/apps/convert-temperature-service.wsdl";

    private static final File TEST_XML_FILE =
        new File(TEST_ROOT_DIR, TEST_XML);

    private static final String TEST_XSL = "com/acme/apps/test.xsl";

    private static final File TEST_XSL_FILE =
        new File(TEST_ROOT_DIR, TEST_XSL);

    private static final String TEST_OUTPUT =
        "com/acme/apps/test.out.xml";

    private static final File TEST_OUTPUT_FILE =
        new File(TEST_ROOT_DIR, TEST_OUTPUT);

    public static String lookupNamespaceUri(final Node currentNode,
            final String prefix) {
        final String namespaceUri;

        namespaceUri =
            currentNode.getOwnerDocument().getDocumentElement()
                .lookupNamespaceURI(prefix);

        return namespaceUri;
    }

    public static String sayHello() {
        return "Hello, world!";
    }

    private Transformer getTransformerFor(final File xsl)
            throws TransformerFactoryConfigurationError,
            TransformerConfigurationException {
        final TransformerFactory transformerFactory =
            TransformerFactory.newInstance();
        final Transformer transformer =
            transformerFactory.newTransformer(new StreamSource(xsl));
        return transformer;
    }

    public void testLookupNamespaceUri()
            throws TransformerConfigurationException,
            TransformerException, IOException {
        final Transformer transformer =
            getTransformerFor(TEST_XSL_FILE);

        transformer.transform(new StreamSource(TEST_XML_FILE),
            new StreamResult(TEST_OUTPUT_FILE));
    }
}

I will create project zip and post it here later.

Adrian.

Michael Ludwig wrote:
Adrian Herscu schrieb:

Imagine few nested loops like the one above...

Tried to enumerate the attributes of the root element and the
namespace attributes are not returned -- any clues?

How about posting a *miniature* example of input XML, XSL and Java code
that reproduces the behaviour you're seeing, along with a description of
how the output doesn't meet your expectations? That might be more likely
to help people figure out what's going on than relying, for the most
part, on imagination.

Michael Ludwig


Reply via email to