Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt about namespace.

 
vivek srivastava
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very much confused about xml name spaces.
I was having one xsl file with following name space
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">..
Now I modified it to
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"
xmlns:xsl="vivek"><xsl:template match="/">

And my application is not working. My question is if namespace means some symbloic grouping then why is the dependency between the program and namespaces and where this dependency comes in java xls transfromation.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

When you modified the namespace name that document stopped being a style-sheet.

In the first version of the document the root tag is

{http://www.w3.org/1999/XSL/Transform}stylesheet

in the second version of the document the root tag is

{vivek}stylesheet

these are fundamentally different elements.

The Java XSL transformation cannot find the stylesheet in the second document as it does not contain a {http://www.w3.org/1999/XSL/Transform}stylesheet root element.

All fully qualified names of the style sheet elements must belong to the {http://www.w3.org/1999/XSL/Transform} namespace and therefore any XSL element begins with {http://www.w3.org/1999/XSL/Transform}

The namespace URI is a global identifier (thats is why URIs were chosen in the first place).

Ronald Bourret's XML Namespaces FAQ
James Clark: XML Namespaces
 
vivek srivastava
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with you.

But where do we define (say) <xsl:for-each select definitions. There should be some place where we define these element�s definition (like for-each) for http://www.w3.org/1999/XSL/Transform name space.

Or is it like all these things are defined in xsl implementation java classes.

My java program is giving error. Is it like my java program check for this string (http://www.w3.org/1999/XSL/Transform) and if it doesn�t fine any show error? But where does java check that the name space should match with the correct value.

I am still confused.
 
vivek srivastava
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with you.

But where do we define (say) <xsl:for-each select definitions. There should be some place where we define these element�s definition (like for-each) for http://www.w3.org/1999/XSL/Transform name space.

Or is it like all these things are defined in xsl implementation java classes.

My java program is giving error. Is it like my java program check for this string (http://www.w3.org/1999/XSL/Transform) and if it doesn�t fine any show error? But where does java check that the name space should match with the correct value.

I am still confused.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vivek srivastava:
But where do we define (say) <xsl:for-each select definitions. There should be some place where we define these element�s definition (like for-each) for http://www.w3.org/1999/XSL/Transform name space.

Or is it like all these things are defined in xsl implementation java classes.


The semantics of the XSLT elements are defined in the XSLT 1.0 and XSLT 2.0 specifications. Those specifications are implemented in the Java XSLT engines (like Saxon) - so there is nothing to "add". The Java engine looks for fully qualified XSLT elements. For example an XSLT engine knows what to do with a {http://www.w3.org/1999/XSL/Transform}for-each element (note: the specification uses xsl:for-each for convenience only; the actual, fully qualified name is {http://www.w3.org/1999/XSL/Transform}for-each).

My java program is giving error. Is it like my java program check for this string (http://www.w3.org/1999/XSL/Transform) and if it doesn�t fine any show error? But where does java check that the name space should match with the correct value.


The XSLT engine is looking for {http://www.w3.org/1999/XSL/Transform}for-each - your document contains {vivek}for-each - a totally different element that has nothing to do which XSLT.

Do you use java.lang.String objects in your Java programs and then suddenly refer to com.vivek.String objects and expect the com.vivek.String objects to come from nowhere and behave like java.lang.String objects? That is what you are essentially expecting XSLT to do.

With xmlns:xsl="http://www.w3.org/1999/XSL/Transform" you are saying that "xsl:" of "xsl:for-each" actually stands for "http://www.w3.org/1999/XSL/Transform" so that every time you mean "{http://www.w3.org/1999/XSL/Transform}for-each" you can actually write "xsl:for-each".

With xmlns:xsl="vivek" "xsl:for-each" actually stands for "{vivek}for-each" which means absolutely nothing to XSLT.
 
vivek srivastava
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot! Its clear now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic