• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

xmlns problem in xslt

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a xslt to transform one xml format A to another xml format B.
During the process, I found if in the source XML A,
any element Tag with "xmlns" attribute like
<sdc xmlns="http://www.sdc.com"> then I can not fetch the subelemnt value
from sdc Node via XSLT.
if I delete the xmlns attribute from sdc node, all works fine.
Should I change something in my XSLT about the xmlns information?
Thanks,
Roy
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The xmlns="foobar" piece, a default namespace definition, in your XML document tells the parser that the element "sdc" is actually "foobar:sdc".
In other words, your XSL needs to do

instead of

[ January 14, 2004: Message edited by: Lasse Koskela ]
 
Roy Huang
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Lasse Koskela
but if I can not directly use the template, waht should I do?
In my case, the source xml file is like:
....
<header>
<sdc xmlns="http://www.abc.com">
<gilt>
<devel>12567</devel>
</gilt>
</sdc>
</header>
...

How can I modify the XSLT with the xmlns?
Like:
....
<develLc>
<xsl:value-of select="header/sdc/gilt/devel"/>
</develLc>
...
to fecth the value 12567?

Roy
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Add this attribute to your stylesheet's root element:

2) Insert the namespace prefix into your XPath expression:
 
Roy Huang
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Lasse,
I have tried the exact same procedure before I
asked you agin with the last reply. But it always gets a
Java IO Null Point Exception, the value 12567 is not fetched.
I use XALAN XSLT, but if I delete the xmlns in Source XML, everything goes fine.
Any idea?
Roy
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post the exact stack trace of that exception?
Oh, one more thing. You may need to add the namespace prefix into the child nodes as well:

[ January 15, 2004: Message edited by: Lasse Koskela ]
 
Roy Huang
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Lasse,
I just tried what you said -> add the xmlns also to the child node, but
the excpetion is still like:
IOException occur: java.lang.NullPointerException
Nothing changed..:-(
Roy
 
Roy Huang
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Lasse,
Sorry, it works, I have made a typing error...
Thanks very much,
Have a nice day,
Roy
 
Roy Huang
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lasse, I have one more question,
In the first case your describe, suppose I have the XSLT like:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="www.abc.com/xyz">
...
<xsl:template match="my:sdc"/>
<xlk version="1.1">
...
</xsl:stylesheet>

actually I want to get the target file like:
<xlk version="1.1">
...
</xlk>

but actually I always get
<xlk xmlns:my="www.abc.com/xyz" version="1.1">
...
<xlk>

U know I don't need the xmlns from XSLT staying in my target xml file,
How can I remove it, what should I set in the XSLT?

Thanks,
Roy
 
Roy Huang
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Find the solution ,
have to write:
<xsl:stylesheet exclude-result-prefixes="my" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="www.sap.com/slim" version="1.0" >

Roy
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic