Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2007, 08:07 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL:output method="text"


Hi all,

I've just started writting my stylesheet for transforming the CALS table into sort of tagged text coding (using <xsl:output method="text">for Indesign), but started getting error at very nascent stage.

ERROR IS: XSL element "template" can be used only on top level


Below is the snippet of my table (I am cutting it short just to give a brief idea )

<?xml version="1.0"?><table id="id_0070956545_001_000195" frame="none" type="numbered" extra-info="Table 1.1">
<title id="id_0070956545_001_000196">Production Possibilities Schedule</title>
<tgroup cols="3">
<colspec colnum="1" colname="c2" align="right"/>
<colspec colnum="2" colname="c2" align="left"/>
<colspec colnum="3" colname="c3" align="char" char="."/>
<thead >
<row>
<entry>as</entry>
<entry>Production of Wheat (Metric tonnes / year)</entry>
<entry>Production of Softwood Lumber (Millions of board-feet / year)</entry>
</row>
</thead>
<tbody id="id_0070956545_001_000202">
.
.
.
.
.</table>

Below is my style sheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="table">&lt;ASCII-MAC&gt;
&lt;Version:4&gt;&lt;FeatureSet:InDesign-Roman&gt;&lt;ColorTable:=&lt;Black:COLOR:CMYK:Proc ess:0,0,0,1&gt;&gt;
&lt;DefineParaStyle:NormalParagraphStyle=&lt;Nexts tyle:NormalParagraphStyle&gt;&gt;
&lt;ParaStyle:NormalParagraphStyle&gt;
&gt;&lt;TableStart:<xsl:value-of select="count(./tgroup/tbody/row)"/>,<xsl:value-of select="string(./tgroup/@cols)"/>,<xsl:value-of select="count(./tgroup/thead/row)"/>,<xsl:value-of select="count(./tgroup/tfoot/row)"/>&lt;tCellDefaultCellType:Text&gt;&gt;&lt;ColStart :&lt;tColAttrWidth:75.9345668452329&gt;&gt;&lt;Col Start:&lt;tColAttrWidth:147.5005&gt;&gt;&lt;ColSta rt:&lt;tColAttrWidth:107.93456684523301&gt;&gt;
</xsl:template>

<xsl:template match="table/thead">
<xsl:if test="count(/table/thead/row)!='0'">
<xsl:for-each select="table/thead/row/entry">

&lt;RowStart:&lt;tRowAttrHeight:60.523913574218746 &gt;&lt;tRowAttrMinRowSize:33.611611111113234&gt;& gt;&gt;&lt;CellStart:1,1&lt;tCellAttrLeftStrokeWei ght:0&gt;&lt;tCellAttrRightStrokeWeight:0&gt;&lt;t CellAttrTopStrokeWeight:0&gt;&lt;tCellAttrBottomSt rokeWeight:0&gt;&gt;&lt;ParaStyle:NormalParagraphS tyle&gt;
<xsl:value-of select="table/tgroup/thead/row/entry[1]"/>&lt;CellEnd:&gt;
</xsl:for-each>
</xsl:if>
</xsl:template>

</xsl:stylesheet>


Can somebody suggest where I am wrong?


Thanks,
Pankaj











__________________
Pankaj
 
Old August 2nd, 2007, 08:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your code looks fine to me. Saxon runs it successfully.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 2nd, 2007, 08:37 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Apologies for not putting my question correctly. It was the error, which I was getting earlier but now runs successfully in both "Sablotron" and "Saxon".

The only thing which is annoying me is that my values with in the (table/thead) is not getting processed in result output.


<xsl:template match="table/thead">
<xsl:if test="count(/table/thead/row)!='0'">
<xsl:for-each select="table/thead/row/entry">

&lt;RowStart:&lt;tRowAttrHeight:60.523913574218746 &gt;&lt;tRowAttrMinRowSize:33.611611111113234&gt;& gt;&gt;&lt;CellStart:1,1&lt;tCellAttrLeftStrokeWei ght:0&gt;&lt;tCellAttrRightStrokeWeight:0&gt;&lt;t CellAttrTopStrokeWeight:0&gt;&lt;tCellAttrBottomSt rokeWeight:0&gt;&gt;&lt;ParaStyle:NormalParagraphS tyle&gt;
<xsl:value-of select="table/tgroup/thead/row/entry[1]"/>&lt;CellEnd:&gt;


EXPECTED RESULT:

<RowStart:<tRowAttrHeight:60.523913574218746><tRow AttrMinRowSize:33.611611111113234>>
<CellStart:1,1<tCellAttrLeftStrokeWeight:0><tCellA ttrRightStrokeWeight:0><tCellAttrTopStrokeWeight:0 ><tCellAttrBottomStrokeWeight:0>><ParaStyle:Normal ParagraphStyle>as<CellEnd:>

 
Old August 2nd, 2007, 09:13 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, your template for match="table" doesn't appear to do an apply-templates, and if it did, then it wouldn't match the template with match="table/thead" because the parent of your thead is a tgroup; and if you fixed that, then the
<xsl:if test="count(/table/thead/row)!='0'"> wouldn't be satisfied (it would throw a type error in 2.0 comparing an integer to a string, and if you fixed that, it would return false, because of the tgroup element); and if you fixed that, then the xsl:for-each wouldn't select anything, because your thead element does not have a child called table.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 2nd, 2007, 10:05 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again Michael. Missing <xsl:apply-templates/>certainly was an error. (I am still improving/working on XSLT)

table/thead was an typo error from side while posting it to forum.

Thanks again.
Pankaj






Similar Threads
Thread Thread Starter Forum Replies Last Post
output xsl in predefined template newuser2525 XSLT 1 December 24th, 2007 08:30 AM
<xsl:output method=”xhtml”> crashes Tomcat li72 XSLT 1 August 13th, 2007 07:30 AM
<xsl:output method=”xhtml”> problem li72 XSLT 5 May 16th, 2007 10:45 AM
XSL html output problem aiyer0912 XSLT 11 November 8th, 2006 07:19 AM
PDF output problem using XSL pulavarthi XSLT 1 November 6th, 2003 05:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.