• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSLT and default namespaces

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


I have an XML document that I transform which has a default namespace. For example:

<root xmlns="http://www.helloworld.com">

</root>

In order for my XSL stylesheet to work with this, I need to specify the following:

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

<xsl:template match="test:root">

</xsl:template>

</xsl:stylesheet>

That all works fine and well, no problems. I now have a near identical XML file that has to be transformed into the same structure. The only difference is that it doesn't contain the default namespace such as my first file example:

<root>

</root>

I am trying to apply the same stylesheet and it is unable to identify any matches in the second file. Is there anyway of making the XSL file compatible with both types of input XML file?

Hope that makes sense,

Thanks,


Stuart
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not that I can envision. You might want to run the second file, the one without a default namespace through a dummy style sheet which just adds the default namespace to the root element. Then use the common namespace aware style sheet. A variation of this would be to use a SAX processor to add the default namespace. something in those lines.

The reason why you use a namespace is to keep elements distinct, even though they have the same name.

- m
 
Stuart Bell
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Madhav,


Thanks for your reply. I managed to get round the problem by using the setAttribute() method on the Element object. This allowed me to set the default namespace on the XML document that didn't contain it. I was then able to apply my stylesheet just as I wanted.

Thanks for your input.

Regards,


Stuart
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic