p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   XSL:output method="text" (http://p2p.wrox.com/showthread.php?t=60749)

Pankaj C August 2nd, 2007 08:07 AM

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












mhkay August 2nd, 2007 08:14 AM

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

Pankaj C August 2nd, 2007 08:37 AM

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:>


mhkay August 2nd, 2007 09:13 AM

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

Pankaj C August 2nd, 2007 10:05 AM

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



All times are GMT -4. The time now is 12:23 AM.

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