Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old November 2nd, 2006, 05:52 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with style

Hi people. I have just started using XSLT and would really appreciate it if someone could look over my work to make sure I have my style correct, and that I am efficient.

I have a word document saved in XML and I want to go through it and extract the tables out of it to create another XML file with just the table information in.

e.g. I want to generate an XML file that goes:

<body>
 <table>
  <row>
   <cell>12</cell>
   <cell>18</cell>
  </row>
  <row>
   <cell>12</cell>
   <cell>18</cell>
  </row>
 </table>
</body>

Here is my current XSL file:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
    version="1.0">
    <xsl:output method="xml"/>

    <xsl:template match="/">
        <body>
            <xsl:for-each select="w:wordDocument/w:body//w:tbl">
                <table>
                    <xsl:for-each select="w:tr">
                        <row>
                            <xsl:for-each select="w:tc">
                                <cell>
                                    <xsl:value-of select="."/>
                                </cell>
                            </xsl:for-each>
                        </row>
                    </xsl:for-each>
                </table>
            </xsl:for-each>
        </body>
    </xsl:template>

</xsl:stylesheet>

This works but I am not sure if this the best way to extract the information. I always like to use good style and be efficient but when I'm not familiar with a language it is hard.

Please cast an eye over this and let me know what you think.

Thanks Boomah.

Oh, and here is an example word xml document with a couple of tables in it:

<?mso-application progid="Word.Document"?>
#8722;
    <w:wordDocument w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no" xml:space="preserve">
<w:ignoreElements w:val="http://schemas.microsoft.com/office/word/2003/wordml/sp2"/>
#8722;
    <o:DocumentProperties>
<o:Title>Table example</o:Title>
<o:Author>ASL</o:Author>
<o:LastAuthor>ASL</o:LastAuthor>
<o:Revision>2</o:Revision>
<o:TotalTime>1</o:TotalTime>
<o:Created>2006-11-01T09:29:00Z</o:Created>
<o:LastSaved>2006-11-01T09:29:00Z</o:LastSaved>
<o:Pages>1</o:Pages>
<o:Words>54</o:Words>
<o:Characters>312</o:Characters>
<o:Company>Aspects Software Limited</o:Company>
<o:Lines>2</o:Lines>
<o:Paragraphs>1</o:Paragraphs>
<o:CharactersWithSpaces>365</o:CharactersWithSpaces>
<o:Version>11.8106</o:Version>
</o:DocumentProperties>
#8722;
    <w:fonts>
<w:defaultFonts w:ascii="Times New Roman" w:fareast="Times New Roman" w:h-ansi="Times New Roman" w:cs="Times New Roman"/>
</w:fonts>
#8722;
    <w:styles>
<w:versionOfBuiltInStylenames w:val="4"/>
<w:latentStyles w:defLockedState="off" w:latentStyleCount="156"/>
#8722;
    <w:style w:type="paragraph" w:default="on" w:styleId="Normal">
<w:name w:val="Normal"/>
#8722;
    <w:rPr>
<wx:font wx:val="Times New Roman"/>
<w:sz w:val="24"/>
<w:sz-cs w:val="24"/>
<w:lang w:val="EN-US" w:fareast="EN-US" w:bidi="AR-SA"/>
</w:rPr>
</w:style>
#8722;
    <w:style w:type="paragraph" w:styleId="Heading1">
<w:name w:val="heading 1"/>
<wx:uiName wx:val="Heading 1"/>
<w:basedOn w:val="Normal"/>
<w:next w:val="Normal"/>
<w:rsid w:val="009B58C3"/>
#8722;
    <w:pPr>
<w:pStyle w:val="Heading1"/>
<w:keepNext/>
<w:spacing w:before="240" w:after="60"/>
<w:outlineLvl w:val="0"/>
</w:pPr>
#8722;
    <w:rPr>
<w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial"/>
<wx:font wx:val="Arial"/>
<w:b/>
<w:b-cs/>
<w:kern w:val="32"/>
<w:sz w:val="32"/>
<w:sz-cs w:val="32"/>
</w:rPr>
</w:style>
#8722;
    <w:style w:type="character" w:default="on" w:styleId="DefaultParagraphFont">
<w:name w:val="Default Paragraph Font"/>
<w:semiHidden/>
</w:style>
#8722;
    <w:style w:type="table" w:default="on" w:styleId="TableNormal">
<w:name w:val="Normal Table"/>
<wx:uiName wx:val="Table Normal"/>
<w:semiHidden/>
#8722;
    <w:rPr>
<wx:font wx:val="Times New Roman"/>
</w:rPr>
#8722;
    <w:tblPr>
<w:tblInd w:w="0" w:type="dxa"/>
#8722;
    <w:tblCellMar>
<w:top w:w="0" w:type="dxa"/>
<w:left w:w="108" w:type="dxa"/>
<w:bottom w:w="0" w:type="dxa"/>
<w:right w:w="108" w:type="dxa"/>
</w:tblCellMar>
</w:tblPr>
</w:style>
#8722;
    <w:style w:type="list" w:default="on" w:styleId="NoList">
<w:name w:val="No List"/>
<w:semiHidden/>
</w:style>
#8722;
    <w:style w:type="table" w:styleId="TableGrid">
<w:name w:val="Table Grid"/>
<w:basedOn w:val="TableNormal"/>
<w:rsid w:val="009B58C3"/>
#8722;
    <w:rPr>
<wx:font wx:val="Times New Roman"/>
</w:rPr>
#8722;
    <w:tblPr>
<w:tblInd w:w="0" w:type="dxa"/>
#8722;
    <w:tblBorders>
<w:top w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
<w:left w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
<w:bottom w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
<w:right w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
<w:insideH w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
<w:insideV w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto"/>
</w:tblBorders>
#8722;
    <w:tblCellMar>
<w:top w:w="0" w:type="dxa"/>
<w:left w:w="108" w:type="dxa"/>
<w:bottom w:w="0" w:type="dxa"/>
<w:right w:w="108" w:type="dxa"/>
</w:tblCellMar>
</w:tblPr>
</w:style>
</w:styles>
#8722;
    <w:shapeDefaults>
<o:shapedefaults v:ext="edit" spidmax="2050"/>
#8722;
    <o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1"/>
</o:shapelayout>
</w:shapeDefaults>
#8722;
    <w:docPr>
<w:view w:val="print"/>
<w:zoom w:val="best-fit" w:percent="114"/>
<w:doNotEmbedSystemFonts/>
<w:proofState w:spelling="clean" w:grammar="clean"/>
<w:attachedTemplate w:val=""/>
<w:defaultTabStop w:val="720"/>
<w:characterSpacingControl w:val="DontCompress"/>
<w:optimizeForBrowser/>
<w:validateAgainstSchema/>
<w:saveInvalidXML w:val="off"/>
<w:ignoreMixedContent w:val="off"/>
<w:alwaysShowPlaceholderText w:val="off"/>
#8722;
    <w:compat>
<w:breakWrappedTables/>
<w:snapToGridInCell/>
<w:wrapTextWithPunct/>
<w:useAsianBreakRules/>
<w:useWord2002TableStyleRules/>
</w:compat>
#8722;
    <wsp:rsids>
<wsp:rsidRoot wsp:val="009B58C3"/>
<wsp:rsid wsp:val="00295713"/>
<wsp:rsid wsp:val="009B58C3"/>
<wsp:rsid wsp:val="00CC24A0"/>
</wsp:rsids>
</w:docPr>
#8722;
    <w:body>
#8722;
    <wx:sect>
#8722;
    <wx:sub-section>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
#8722;
    <w:r>
<w:t>Table example</w:t>
</w:r>
</w:p>
<w:p wsp:rsidR="009B58C3" wsp:rsidRDefault="009B58C3"/>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:r>
<w:t>Some example tables for transforming!!!</w:t>
</w:r>
</w:p>
<w:p wsp:rsidR="009B58C3" wsp:rsidRDefault="009B58C3"/>
#8722;
    <w:tbl>
#8722;
    <w:tblPr>
<w:tblStyle w:val="TableGrid"/>
<w:tblW w:w="0" w:type="auto"/>
<w:tblLook w:val="01E0"/>
</w:tblPr>
#8722;
    <w:tblGrid>
<w:gridCol w:w="1771"/>
<w:gridCol w:w="1771"/>
<w:gridCol w:w="1771"/>
<w:gridCol w:w="1771"/>
<w:gridCol w:w="1772"/>
</w:tblGrid>
#8722;
    <w:tr wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidTr="009B58C3">
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="8856" w:type="dxa"/>
<w:gridSpan w:val="5"/>
<w:shd w:val="clear" w:color="auto" w:fill="000080"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:b/>
<w:color w:val="FFFFFF"/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:b/>
<w:color w:val="FFFFFF"/>
</w:rPr>
<w:t>Table Header</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
#8722;
    <w:tr wsp:rsidR="009B58C3" wsp:rsidTr="009B58C3">
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
<w:t>11</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
<w:t>21</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
<w:t>31</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
<w:t>41</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1772" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
<w:t>51</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
#8722;
    <w:tr wsp:rsidR="009B58C3" wsp:rsidTr="009B58C3">
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
<w:t>12</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
<w:t>22</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
<w:t>32</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
<w:t>42</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1772" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:i/>
</w:rPr>
<w:t>52</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
#8722;
    <w:tr wsp:rsidR="009B58C3" wsp:rsidTr="009B58C3">
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
<w:t>13</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
<w:t>23</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
<w:t>33</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
<w:t>43</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1772" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
</w:pPr>
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:color w:val="FF0000"/>
</w:rPr>
<w:t>53</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
<w:p wsp:rsidR="009B58C3" wsp:rsidRDefault="009B58C3"/>
<w:p wsp:rsidR="009B58C3" wsp:rsidRDefault="009B58C3"/>
<w:p wsp:rsidR="00295713" wsp:rsidRDefault="00295713"/>
#8722;
    <w:p wsp:rsidR="00295713" wsp:rsidRDefault="00295713">
#8722;
    <w:pPr>
#8722;
    <w:sectPr wsp:rsidR="00295713">
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:line-pitch="360"/>
</w:sectPr>
</w:pPr>
#8722;
    <w:r>
<w:t>Blah </w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
#8722;
    <w:r>
<w:t>blah</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
#8722;
    <w:r>
<w:t> blah</w:t>
</w:r>
</w:p>
#8722;
    <w:tbl>
#8722;
    <w:tblPr>
<w:tblStyle w:val="TableGrid"/>
<w:tblW w:w="0" w:type="auto"/>
<w:tblLook w:val="01E0"/>
</w:tblPr>
#8722;
    <w:tblGrid>
<w:gridCol w:w="1771"/>
<w:gridCol w:w="1771"/>
<w:gridCol w:w="1771"/>
<w:gridCol w:w="1771"/>
<w:gridCol w:w="1772"/>
</w:tblGrid>
#8722;
    <w:tr wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidTr="009B58C3">
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="8856" w:type="dxa"/>
<w:gridSpan w:val="5"/>
<w:shd w:val="clear" w:color="auto" w:fill="000080"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:b/>
<w:color w:val="FFFFFF"/>
</w:rPr>
</w:pPr>
#8722;
    <w:r>
#8722;
    <w:rPr>
<w:b/>
<w:color w:val="FFFFFF"/>
</w:rPr>
<w:t>Table 2</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
#8722;
    <w:tr wsp:rsidR="009B58C3" wsp:rsidTr="009B58C3">
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r>
<w:t>Empty cells follow</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
<w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3"/>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
<w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3"/>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
<w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3"/>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1772" w:type="dxa"/>
</w:tcPr>
<w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3"/>
</w:tc>
</w:tr>
#8722;
    <w:tr wsp:rsidR="009B58C3" wsp:rsidTr="009B58C3">
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r wsp:rsidRPr="009B58C3">
<w:t>“31231”</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
<w:vmerge w:val="restart"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r>
<w:t>Merged cells vertically</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r>
<w:t>Some more text</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r>
<w:t>Blah </w:t>
</w:r>
<w:proofErr w:type="spellStart"/>
#8722;
    <w:r>
<w:t>blah</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1772" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r>
<w:t>Includes < and > characters</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
#8722;
    <w:tr wsp:rsidR="009B58C3" wsp:rsidTr="009B58C3">
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r>
<w:t>Cell including some structure.</w:t>
</w:r>
</w:p>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:pPr>
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
</w:pPr>
</w:p>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r wsp:rsidRPr="009B58C3">
#8722;
    <w:rPr>
<w:b/>
</w:rPr>
<w:t>This is a new paragraph in bold.</w:t>
</w:r>
</w:p>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
<w:vmerge/>
</w:tcPr>
<w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3"/>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="1771" w:type="dxa"/>
</w:tcPr>
<w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3"/>
</w:tc>
#8722;
    <w:tc>
#8722;
    <w:tcPr>
<w:tcW w:w="3543" w:type="dxa"/>
<w:gridSpan w:val="2"/>
</w:tcPr>
#8722;
    <w:p wsp:rsidR="009B58C3" wsp:rsidRPr="009B58C3" wsp:rsidRDefault="009B58C3" wsp:rsidP="009B58C3">
#8722;
    <w:r>
<w:t>Merged cells horizontally</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
<w:p wsp:rsidR="009B58C3" wsp:rsidRDefault="009B58C3"/>
<w:proofErr w:type="gramStart"/>
#8722;
    <w:p wsp:rsidR="00295713" wsp:rsidRDefault="00295713">
#8722;
    <w:r>
<w:t>Some more text.</w:t>
</w:r>
<w:proofErr w:type="gramEnd"/>
</w:p>
#8722;
    <w:sectPr wsp:rsidR="00295713">
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:line-pitch="360"/>
</w:sectPr>
</wx:sub-section>
</wx:sect>
</w:body>
</w:wordDocument>
  #2 (permalink)  
Old November 2nd, 2006, 07:11 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Not a bad start. I would be inclined to use <xsl:apply-templates/> in places where you have used xsl:for-each or xsl:value-of select=".". That's especially with "document-oriented XML" where elements in the input document may occur in unexpected places. For example, tables might be nested one inside another.

So instead of

<xsl:template match="/">
        <body>
            <xsl:for-each select="w:wordDocument/w:body//w:tbl">
                <table>
                    <xsl:for-each select="w:tr">
                        <row>
                            <xsl:for-each select="w:tc">
                                <cell>
                                    <xsl:value-of select="."/>
                                </cell>
                            </xsl:for-each>
                        </row>
                    </xsl:for-each>
                </table>
            </xsl:for-each>
        </body>
    </xsl:template>

you want something more like:

<xsl:template match="*">

  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()">

</xsl:template>

<xsl:template match="/">
        <body>
            <xsl:apply-templates/>
        </body>
</xsl:template>

<xsl:template match="w:tbl">
                <table>
                    <xsl:apply-templates/>
                </table>
</xsl:template>

and so on.

One other point:

    <xsl:template match="//w:t">

appears in the email version of your posting but not in the forum version (how did you manage that???). Better to write match="w:t". Both match a w:t element anywhere in the document (the // is redundant). But the "//" changes the default priority of the rule, which can cause unexpected bugs if there are multiple rules that match the same elements.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old November 2nd, 2006, 08:12 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael, thanks very much for the reply.

I have updated my XSL file to:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
    version="1.0">
    <xsl:output method="xml"/>

    <xsl:template match="*">

        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="text()">

    </xsl:template>

    <xsl:template match="/">
        <body>
            <xsl:apply-templates/>
        </body>
    </xsl:template>

    <xsl:template match="w:tbl">
        <table>
            <xsl:apply-templates/>
        </table>
    </xsl:template>

    <xsl:template match="w:tr">
        <row>
            <xsl:apply-templates/>
        </row>
    </xsl:template>

    <xsl:template match="w:tc">
        <cell>
            <xsl:value-of select="."/>
        </cell>
    </xsl:template>

</xsl:stylesheet>

as suggested and it works just like before. I do have a new problem though. Before I changed the xsl file I had added on some extra logic. It had been updated to:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
    version="1.0">
    <xsl:output method="xml"/>

    <xsl:template match="/">
        <body>
            <xsl:for-each select="w:wordDocument/w:body//w:tbl[ (w:tr/w:tc='Profile_List') or
                                                                 (w:tr/w:tc='Table Header')]">
                <table>
                    <xsl:for-each select="w:tr">
                        <row>
                            <xsl:for-each select="w:tc">
                                <cell>
                                    <xsl:value-of select="."/>
                                </cell>
                            </xsl:for-each>
                        </row>
                    </xsl:for-each>
                </table>
            </xsl:for-each>
        </body>
    </xsl:template>

</xsl:stylesheet>

Here I filter depending on the contents of the first cell in each table because I am only interested in certain tables. This works as I expect.

The problem is I can't get it to work with the new style. If I put the condition in the place I expect, it still selects all tables:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
    version="1.0">
    <xsl:output method="xml"/>

    <xsl:template match="*">

        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="text()">

    </xsl:template>

    <xsl:template match="/">
        <body>
            <xsl:apply-templates/>
        </body>
    </xsl:template>

    <xsl:template match="w:tbl[(w:tr/w:tc='Table Header') or (w:tr/w:tc='Table Header')]">
        <table>
            <xsl:apply-templates/>
        </table>
    </xsl:template>

    <xsl:template match="w:tr">
        <row>
            <xsl:apply-templates/>
        </row>
    </xsl:template>

    <xsl:template match="w:tc">
        <cell>
            <xsl:value-of select="."/>
        </cell>
    </xsl:template>

</xsl:stylesheet>

I know I'm doing something a bit silly, I just don't know what! :o)

Any ideas?

Cheers, Boomah.

  #4 (permalink)  
Old November 2nd, 2006, 08:57 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Firstly, the two branches of your "or" are the same:

w:tbl[(w:tr/w:tc='Table Header') or (w:tr/w:tc='Table Header')]">


More importantly, you need to decide what to do with the w:tbl elements that don't match this predicate. At the moment your match="*" rule will kick in, so you'll hit the w:tr elements and output rows without a table to contain them. The equivalent to your for-each is to skip such tables entirely. Use an empty template rule:

<xsl:template match="w:tbl"/>

This has lower priority than the rule with a predicate, so it provides a fallback. (Provided you don't write it as match="//w:tbl"!)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #5 (permalink)  
Old November 2nd, 2006, 09:19 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again.

The branches was just a typo when copying across. :( I need to wake up!!

Anyway, it works now and is doing exactly what I want it to do.

Thanks a lot!!!!

Regards, Boomah.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Style wiegel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 February 27th, 2007 09:28 PM
hyperlinks style scrowler CSS Cascading Style Sheets 8 January 20th, 2005 09:13 AM
a: hover - style... elladi Dreamweaver (all versions) 2 August 3rd, 2004 06:48 AM
difference between style.visibility and style.disp Mimi Javascript How-To 6 September 17th, 2003 11:50 PM





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