470,647 Members | 1,230 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

XSL xmlns usage problems during transform

Hi

I have problems with transforming a xml document with Xalan and
javax.xml.Transformer.

Following xsl is used:
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:java="java"
xmlns:convert="com.foo.Class">

<xsl:output method="xml"
encoding="UTF-8"
indent="yes"
xalan:indent-amount="2"/>
<and so on with specific transformation>
</xsl:stylesheet>

The xml parsed have the followin format:
<?xml version="1.0" encoding="utf-16"?>
<MessageHeader xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.foo2.com/XMLSchema/Envelope">
<Message xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
messageId="EMI20051026093900046"
xmlns="http://www.foo2.com/Schema.xsd">

<and so on with specific tags>
The problem I have is that the transformation, that earlier worked
fine, has stopped to work. The only differense is the last part of the
given xml. It has changed from:
xmlns=""
to
xmlns="http://www.foo2.com/Schema.xsd"

And the transformation stopps early without transforming the rest of
the document.
Questions:
What does the xmlns field do actually?
Can one override the xmlns field?
Any other solutions?

Remember that the xml given is from a another part and we cant control
the xml sent to us.

Thank you for your help
JŲrgen

Oct 26 '05 #1
1 5261


jo************@gmail.com wrote:

Following xsl is used:
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:java="java"
xmlns:convert="com.foo.Class"> The xml parsed have the followin format:
<?xml version="1.0" encoding="utf-16"?>
<MessageHeader xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.foo2.com/XMLSchema/Envelope">


The problem is that various elements are in a default namespace defined
with xmlns="namespaceURI" so those elements have a name without a prefix
(e.g. MessageHeader) but are in a certain namespace.
To match that with XPath 1.0 you need to bind a prefix to the default
namespace and use that prefix in XPath expressions and XSLT match
matterns. No change is needed on the XML input but inside of the
stylesheet you need to add e.g.
xmlns:pf1="http://www.foo2.com/XMLSchema/Envelope"
xmlns:pf2="http://www.foo2.com/Schema.xsd"
on the xsl:stylesheet element, then your XPath expressions can look alike
/pf1:MessageHeader/pf2:Message
to select elements in the namespaces bound to the prefixes used.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 26 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Rosa M™ Gůmez Flores | last post: by
3 posts views Thread by Mike Dickens | last post: by
11 posts views Thread by ma740988 | last post: by
7 posts views Thread by Simon Hart | last post: by
reply views Thread by R. Ian Lee | last post: by
2 posts views Thread by shaun roe | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.