Newbie - Help with transformation

R

Rey

Howdy all.

Read and worked through the XSLT part of Castro's XML for the World Wide
web. Then tried to apply to a test case and get the following:
- no table is displayed, i.e. no header, no tbl frame

When I started this yesterday, I got 3 header displays but no table frame;
made a change then got the 3 ItemID numbers but all in a row w/no separation
and still no table frame.
Had tried using the apply-templates meth for the table data fields with
matching templates but no success. Then tried using value-of - still no
success.

Have validated the XML file using the w3schools page
(http://www.w3schools.com/dom/dom_validate.asp) - no errs.

Appreciate if you could provide suggestion/comments on what I'm doing wrong.
Looking at getting the XSLT for dummies book but also reading through the
XSLT transformation tutorial at w3.org
(http://www.w3.org/TR/1999/REC-xslt-19991116).

Some additional questions:
what's the difference between XSLT v 1.0 and 2.0.?

In the Catro book, she uses subspecies in the for-each select part to
display table rows while the w3schools approach (catalog/cd example) uses
catalog/cd. Guess both are correct, but does this mean that you need to
specify the path to the rows in order to display them in the table? Is there
a shortcut way of specifying a long path by using a variable similar to
SUBST in DOS?

Thank you in advance for your help,

Rey
XML and XSL files below

***************************
XML file:

<?xml-stylesheet type="text/xsl" href="MikeCertTest.xsl"?>
<Root TestName="Designing and Implementing Distributed Applications with
Microsoft Visual Basic 6.0"><Item ItemID="784199"
QuestionItemType="12"><ItemType><item
type="fusion"><question><validationmap><INPUT_Group1>RB_0</INPUT_Group1></va
lidationmap><options><labelquest><div>Why can an ActiveX DLL not be assigned
an Instancing property of SingleUse?</div><br/></labelquest><table><tr><td
valign="top"><input type="radio" name="INPUT_Group1" id="RB_0"
value="RB_0"/></td><td for="RB_0"><label> because it is an in-process
component</label></td></tr></table></options></question></item>
</ItemType><SectionDescription>Creating and Managing COM
Components</SectionDescription></Item><Item ItemID="784184"
QuestionItemType="12"><ItemType><item
type="fusion"><question><validationmap><INPUT_Group1>RB_0</INPUT_Group1></va
lidationmap><options><labelquest><div>Which object is the base object used
to create an ActiveX control?</div><br/></labelquest><table><tr><td
valign="top"><input type="radio" name="INPUT_Group1" id="RB_0"
value="RB_0"/></td><td for="RB_0"><label>
UserControl</label></td></tr></table></options></question></item>
</ItemType><SectionDescription>Creating and Managing COM
Components</SectionDescription></Item><Item ItemID="784152"
QuestionItemType="12"><ItemType><item
type="fusion"><question><validationmap><INPUT_Group1>RB_0</INPUT_Group1></va
lidationmap><options><labelquest><div>Why would you use the Friend keyword
when declaring a procedure within a class
module?</div><br/></labelquest><table><tr><td valign="top"><input
type="radio" name="INPUT_Group1" id="RB_0" value="RB_0"/></td><td
for="RB_0"><label> You want other classes within the component to use the
procedure, but not other client
applications.</label></td></tr></table></options></question></item>
</ItemType><SectionDescription>Creating and Managing COM
Components</SectionDescription></Item>
</Root>


**************
XSL file:

<?xml version="1.0"?>

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- applied to root node of xml document -->
<xsl:template match="/">
<!-- output to html -->
<html>
<head>
<title>Test Output - Answers to Certification Exam Questions</title>
</head>

<body bgcolor="white">

<!--   is for non-breaking space -->
<!-- get/display test name -->
<p><b>Test Name:  </b><xsl:value-of
select="Root/@testname"/></p>

<xsl:apply-templates
select="Root/Item"/>

</body>

</html>

</xsl:template>


<xsl:template match="Item">
<table width="100%" border="1" >

<tr><th>ItemID</th><th>Question</th><th>Answer</th><th>Section
Description</th></tr>

<!-- loop thru each Q & A -->
<xsl:for-each select="ItemType">

<tr>
<td><xsl:value-of
select="Item/@ItemID"/></td>

<td><xsl:value-of
select="div"/></td>

<td><xsl:value-of select="label"/></td>

<td><xsl:value-of
select="SectionDescription"/></td>

</tr>

</xsl:for-each>

</table>

</xsl:template>


<xsl:template match="Item"><b><xsl:value-of
select="Item[@ItemID]"/></b></xsl:template>

<xsl:template match="div"><xsl:value-of select="."/></xsl:template>

<xsl:template match="label"><xsl:value-of select="."/></xsl:template>

<xsl:template match="SectionDescription"><xsl:value-of
select="."/></xsl:template>


</xsl:stylesheet>
 
J

Joris Gillis

Hi,
When I started this yesterday, I got 3 header displays but no table frame;
made a change then got the 3 ItemID numbers but all in a row w/no separation
and still no table frame.
Had tried using the apply-templates meth for the table data fields with
matching templates but no success. Then tried using value-of - still no
success.

I think the stylesheet you need looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="html" indent="yes"/>

<!-- applied to root node of xml document -->
<xsl:template match="/">
<!-- output to html -->
<html>
<head>
<title>Test Output - Answers to Certification Exam Questions</title>
</head>
<body bgcolor="white">
<!--   is for non-breaking space -->
<!-- get/display test name -->
<p><b>Test Name:  </b><xsl:value-of
select="Root/@testname"/></p>
<xsl:apply-templates select="Root"/>
</body>
</html>
</xsl:template>


<xsl:template match="Root">
<table width="100%" border="1" >
<tr><th>ItemID</th><th>Question</th><th>Answer</th><th>Section
Description</th></tr>
<!-- loop thru each Q & A -->
<xsl:for-each select="Item">
<tr>
<td><xsl:value-of select="@ItemID"/></td>
<td><xsl:value-of select=".//div"/></td>
<td><xsl:value-of select=".//label"/></td>
<td><xsl:value-of select=".//SectionDescription"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>


<xsl:template match="@ItemID"><b><xsl:value-of select="."/></b></xsl:template>

</xsl:stylesheet>

the reason for the table not being setup was that you had two template that match the 'Item' node.

Hope this helps.

regards,
 
R

Rey

Howdy, Joris.
Thanks for the quick help.
You were correct in that there were 2 Item template matches - can't see the
forest for the trees :cool:. Fixing that displayed the table frame or should I
say 3 table headers.

Then, I changed the apply template in the root section to Root/Item with a
coresponding change from Root match to Item match. This then caused the 3
rows to display in the table. However, the ItemID and SectionDescription
data does not display.

Thanks again for the help as now I at least "see" data :cool:,

Rey

Joris Gillis said:
Hi,


I think the stylesheet you need looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="html" indent="yes"/>

<!-- applied to root node of xml document -->
<xsl:template match="/">
<!-- output to html -->
<html>
<head>
<title>Test Output - Answers to Certification Exam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top