Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Newbie - Help with transformation

Reply
Thread Tools

Newbie - Help with transformation

 
 
Rey
Guest
Posts: n/a
 
      06-25-2005
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_Grou p1>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_Grou p1>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_Grou p1>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"
xmlnssl="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>



 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      06-25-2005
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xslutput 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,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Vincit omnia simplicitas
Keep it simple
 
Reply With Quote
 
 
 
 
Rey
Guest
Posts: n/a
 
      06-25-2005
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 . 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 ,

Rey

"Joris Gillis" <> wrote in message
news...
> 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"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">
>
> <xslutput 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,
> --
> Joris Gillis (http://users.telenet.be/root-jg/me.html)
> Vincit omnia simplicitas
> Keep it simple



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on XLS transformation ???? =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?= ASP .Net 0 02-10-2006 09:18 AM
Newbie XML transformation question using XSL icedgar XML 1 02-07-2005 06:24 PM
XSL Transformation output -- no tags -- Help! Mike Conmackie XML 4 04-29-2004 04:06 PM
XSL transformation in an applet (HELP) coincoin Java 0 08-05-2003 09:09 AM
Need help on SQL-Server Network Data Transformation Muhammad Qasim MCSD 1 07-09-2003 08:40 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57