Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL for XML database 1

Status
Not open for further replies.

cathiec

Programmer
Oct 21, 2003
139
IE
Hello there!
I have the following simple XML database:

<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet href = &quot;sample.xsl&quot; type = &quot;text/xsl&quot;?>
<!DOCTYPE Quiz SYSTEM &quot;sample.dtd&quot;>

<Quiz Status=&quot;NewVersion&quot;>
<QuestionsAnswers QuestionNumber=&quot;1&quot;

Question=&quot;1&quot;


Answer1 =&quot;correct&quot;
Answer2 =&quot;correct&quot;
Answer3 =&quot;correct&quot;
Answer4 =&quot;correct&quot;
/>

</Quiz>

The following dtd describes the Database:

<?xml version=&quot;1.0&quot;?>
<!ELEMENT Quiz (QuestionsAnswers*)>
<!ATTLIST Quiz
Status (NewVersion | UpdatedVersion | CourtesyCopy) #REQUIRED>
<!ELEMENT QuestionsAnswers EMPTY>
<!ATTLIST QuestionAnswers
QuestionNumber CDATA #REQUIRED
Question CDATA #REQUIRED
Answer1 CDATA #REQUIRED
Answer2 CDATA #REQUIRED
Answer3 CDATA #REQUIRED
Answer4 CDATA #REQUIRED
>

I am trying to create an xsl stylesheet that will display the question and then underneath this the four answers each with a corresponding radio button. All I have is the following:

<?xml version = &quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl = &quot; version = &quot;1.0&quot;>
<xsl:eek:utput method = &quot;html&quot;/>

<xsl:template match = &quot;Quiz&quot;>

<body bgcolor = &quot;#FFDDFF&quot;>
<p><xsl:apply-templates/></p>
</body>
</xsl:template>
</xsl:stylesheet>

I really would appreciate any help as my xsl skills are quite basic

regards,
cathie
 
I think your XML is bad: you've left yourself no way to iterate through your attributes in a meaningful way without examining the name of each attribute, which just makes it all harder. (You've included data in the attribute names themselves. Bad form.) Wouldn't something like this be better:
Code:
<?xml version=&quot;1.0&quot;?>
<quiz status=&quot;New Version&quot;>
  <item number=&quot;1&quot;>
    <question>When did Columbus discover America?
      <answer choice=&quot;A&quot;>1492</answer>
      <answer choice=&quot;B&quot;>Columbus didn't discover America, Indians did.</answer>
      <answer choice=&quot;C&quot;>Columbus was a putz: he thought he was in India.</answer>
      <answer choice=&quot;D&quot;>Columbus didn't discover America, native Americans did.</answer>
    </question>
  </item>
</quiz>

Now, you can use an XSL template to select the
Code:
answer
nodes and output whatever you want.

IOW, if you put more thought into the XML (i.e., structuring the data) and how you're going to use it, the XSL will be less of a problem.

HTH,
harebrain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top