File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes doubt about namespace. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "doubt about namespace." Watch "doubt about namespace." New topic
Author

doubt about namespace.

vivek srivastava
Ranch Hand

Joined: Nov 30, 2007
Posts: 39
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

Joined: Aug 19, 2005
Posts: 2922
    
    5
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

Joined: Nov 30, 2007
Posts: 39
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

Joined: Nov 30, 2007
Posts: 39
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

Joined: Aug 19, 2005
Posts: 2922
    
    5
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

Joined: Nov 30, 2007
Posts: 39
Thanks a lot! Its clear now.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt about namespace.