Sunday, November 26, 2006

XML hints

These are some things needed to know about xml.....

Fact 1:
Comments should not have '--' in between.. This is a very common knowledge but what is not so common knowledge is that '--->' is an invalid end of comment.
ref:- http://www.w3.org/TR/2004/REC-xml-20040204/#sec-comments

Fact 2:
Do you know about dtd entities?

<!ENTITY copyright SYSTEM "http://www.w3schools.com/dtd/entities.dtd">

You define a dtd entity and then it can be used in the dtd anywhere, its like a constant being declared.

It can be used in xml as:-
<author>&writer;©right;</author>
ref:- http://www.w3schools.com/dtd/dtd_entities.asp

Fact 3
Now whats the difference between a/b and a[b] in XPath?

a/b selects the node b which is a child of node a.
a[b] selects node a which has a child b.

The difference is very subtile but the node selected is different.

Fact 4
What does the translate function in XSLT do:-
translate("abcdef--","ab-","AB")

will result in:-
ABcdef

ref:- http://www.w3.org/TR/xpath#section-String-Functions

Fact 5

Stylesheet Inclusion
It is an error if a stylesheet directly or indirectly includes itself.

Including a stylesheet multiple times can cause errors because of duplicate definitions. Such multiple inclusions are less obvious when they are indirect. For example, if stylesheet B includes stylesheet A, stylesheet C includes stylesheet A, and stylesheet D includes both stylesheet B and stylesheet C, then A will be included indirectly by D twice. If all of B, C and D are used as independent stylesheets, then the error can be avoided by separating everything in B other than the inclusion of A into a separate stylesheet B' and changing B to contain just inclusions of B' and A, similarly for C, and then changing D to include A, B', C'.

This can be tested by having templates of the same name in all the stylesheets and play around with importing the style sheets. Thus u'll notice
1. the curent style sheet takes the precidence
2. if more than one stylesheets are included then the last one imported takes precidence.

ref:- http://www.w3.org/TR/xslt#import

No comments: