Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Namespace Issues

 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to produce another XML from an existing XML using XSLT (XML + XSLT = XML), and I'm experiencing namespaces issue. I'm new to this, so I guess the solution might be easy, anyways I'm still confused about handling this.

Scenario A:
---
XML input:
<metadata xmlns="http://www.mycompany.com/schema/odsload" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

XML output:
Contains just data inside the XML input elements


Scenario B:
---
XML input:
<metadata xmlns:ods="http://www.mycompany.com/schema/odsload" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

XML output:
Ok, I've got a well structured XML

Can anybody tell me please what's going on?

Thanks!
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose there is more code in your XSLT than you actually posted there. Probably it is trying to match on element names. When you match on an element name, you are trying to match that name with no namespace (that's an XPath 1.0 default). That fails to match that name in the default namespace, which is what's going on in the first example.
 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying Paul. Do you know a better solution for addressing this issue, once I can't modify the XML input? Adding "ds" to xmlns is definitely an ugly workaround
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead ofwhich doesn't match a "thing" element in the default namespace, you can do this:That matches either a "thing" element in the default namespace or a "thing" element not in any namespace.
[ May 03, 2007: Message edited by: Paul Clapham ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic