NAME.XML
<?xml version="1.0">
<!DOCTYPE NameList SYSTEM "Name.dtd">
<NameList
id="Root">
<Name1>Chris</Name1>
</NameList>
NAME.XSL
<xsl:stylesheet>
<xsl:template match="/">
<HTML>
<BODY>
<B>ROOT</B>
<xsl:process-children/>
</BODY>
</HTML>
</xsl:template>
<xsl:template
match="./*[first-of-any()]">
<B>CHILD</B>
</xsl:template>
</xsl:stylesheet>
Assuming Name.xsl is given Name.xml
for processing, The output would be :-
ROOT
CHILD
But ideally, I should have
got
ROOT
CHILD
CHILD
This is because in Name.xml
<NameList> contains 2 children <Name1> and <Name2>.This
hierarchy reflects the complete structural information regarding Name.xml. But
this kind of hierarchy is not possible if Name.xml is given to Name.xsl for
processing since Name.xml conatins only <Name1>.
So what shall I do to make an XSL
stylesheet reflect the entire structural information regarding an XML
file?
I have a few approaches. If someone
could kindly comment on them, I'd be grateful. Any additions and new suggestions
would be great!
APPROACH 1 :- All the elements defined in a DTD should be
present in all conforming XML files, if an XSL stylesheet is to display the
entire structural information.This would mean even if a conforming xml file does
not need an element defined optional in the DTD , it would have to represented
as empty.
Would not this approach be overburdening for XML files and
lead to overpopulation of elements?
APPROACH 2 :-The DTD contains structural information regarding
it's conforming xml files. Since it is desired to output structural information
using XSL, the DTD should be given to the XSL stylesheet instead of conforming
xml files, in order to get the complete structural information.
But then XSL was never made to parse DTDs. It works only on
XML files. Right/Wrong?
Will this approach work?
APPROACH 3 :- How about making XSchema's (or any other schema
lang. file which uses XML syntax to describe structural info.) for all those xml
files for which I want to output structural information using XSL? This would
work fine since
- Schema's are XML files
- Schema's given as input to the XSL processor will ensure
that the entire structural info. regarding conforming xml files will be
outputted using XSL stylesheet.
I feel that APPROACH 3 is the best, and APPROACH 1 would have
also been good, but then XSL cannot process DTDs. Why this
injustice?
Thanks in advance for any help,
AMIT