Advice needed on relating XSL pattern rules to XML instance/meta data

Subject: Advice needed on relating XSL pattern rules to XML instance/meta data
From: "Amit Rekhi" <amitr@xxxxxxxxxxxxx>
Date: Fri, 6 Nov 1998 19:14:14 +0530
This ques. turned out longer than I expected, Hope someone has the patience to read the whole thing , Thanks :-)
 
Hello All,
                I am currently working on designing an XSL stylesheet which would output the structure for an XML file which the XSL file takes for processing. 
                But then it is not necessary that a XML file totally reflects all the elements that are declared in it's DTD. An XML file may not contain elements that are declared optional in it's DTD.Consequently, an XSL stylesheet trying to output the structural information for an XML file may not output the entire element hierarchy as given in the xml file's DTD.
 
                I'll explain my scenario with an example.
                Let's say I have an XML file (say Name.xml)
 
                                                NAME.DTD
            <!ELEMENT NameList (Name1,Name2*)>
                <!ATTLIST NameList
                                          id ID #IMPLIED>
            <!ELEMENT Name1(#PCDATA)>
            <!ELEMENT Name2(#PCDATA)>
 
 
                                                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 
 
 
Current Thread