aspose file tools*
The moose likes XML and Related Technologies and the fly likes Name space from xslt into transformed xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Name space from xslt into transformed xml" Watch "Name space from xslt into transformed xml" New topic
Author

Name space from xslt into transformed xml

John Robert
Ranch Hand

Joined: Jun 17, 2008
Posts: 39
Hello,
I have a couple of questions

1.My xslt uses namespace because the input xml(the xml being transformed) uses a name space. In my transformed xml I see the name spaces I used in the xslt, even thought I do not have any elements from the name space in my transformed xml. Is there a way to ask the xslt to not include these name spaces?

2. Is it considered a xsd validation error, if the xml has additional name spaces , than what the xsd contains?

Thank you.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

John Robert wrote:1.My xslt uses namespace because the input xml(the xml being transformed) uses a name space. In my transformed xml I see the name spaces I used in the xslt, even thought I do not have any elements from the name space in my transformed xml. Is there a way to ask the xslt to not include these name spaces?


Well, unused namespace declarations don't do anything except take up a little bit of space, so they aren't really a big problem. However I believe there's an attribute of the <xsl:output> element which allows you to exclude them -- I don't remember what it is right now but I do remember having used it myself. (Even though the unused namespace declarations didn't make any difference, I too still wanted to get rid of them.)

2. Is it considered a xsd validation error, if the xml has additional name spaces , than what the xsd contains?


I don't know much about Schema but I would find it very unlikely for validation to care about something which makes no difference to the meaning of the document. I suppose you could try it yourself to see what happens.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
Q1.
My xslt uses namespace because the input xml(the xml being transformed) uses a name space. In my transformed xml I see the name spaces I used in the xslt, even thought I do not have any elements from the name space in my transformed xml. Is there a way to ask the xslt to not include these name spaces?

A1. If your xslt uses namespaces not that appeared in the input xml, such as some xslt-extension-functionality etc..., and that those namespaces would not matter in any material sense in the output xml, you can search and use xsl:exclude-result-prefixes, with value of a space separated list of prefixes involved to achieve the purpose. If your xslt uses namespaces because it needs so for matching the input xml, then it is very much trickier. Basically, you need to completely "rewrite" the output to achieve the purpose. "rewrite" in this sense: you refrain from using xsl:copy-of and xsl:copy. For xsl:copy-of it might be easier to understand because it will output what appears in the input xml hence, you cannot stop those namespaces appearing in the output. For xsl:copy, it is harder to understand. In some case, you make xsl:copy of nodes which are namespace-blind, such as text nodes, but the effect is that it is not a complete "rewrite" of the output and you cannot stop input's namespace appearing in the output document. All it sounds very confusing... it is. Maybe after one has had dealt with many xml, one may come to term with that subtlety.

Q2.
Is it considered a xsd validation error, if the xml has additional name spaces , than what the xsd contains?

A2. No, it is not and it should not matter.
John Robert
Ranch Hand

Joined: Jun 17, 2008
Posts: 39
Thanks for the responses. Those did help me understand what I am looking for better. I just realized I never responded back. Thanks and sorry about that.
 
 
subject: Name space from xslt into transformed xml