Solved

XSLT retaining undesired text

Posted on 2004-09-20
3
459 Views
Last Modified: 2008-02-01
Hi There,

I am a relatively newbie to XSLT and am having the following issue:
I want to perform an XSL transformation on an xml file, which is generated from an office spreadsheet web comopent, so as to display only the cell values (Data tags)  for each row (Workbook/Worksheet/Table/Row/Cell tags). However, I'm also getting the text contained in other tags: in this case the <c:ComponentOptions> tag values. How can I restrict the transformation so asto display only the values for each row?
The results would be displayed on the browser, so the output needsto be HTML.

Many thanks for your help!

My XSLT file is:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"             
      xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:x="urn:schemas-microsoft-com:office:excel"                               
      xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
      xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
      xmlns:html="http://www.w3.org/TR/REC-html40"
      exclude-result-prefixes="c x o html"
>
      <xsl:output method="html" indent="yes"/>
      <xsl:template match="/ss:Workbook/ss:Worksheet[@Name='Test']">
            <xsl:apply-templates/>            
      </xsl:template>

      <xsl:template match="ss:Table/ss:Row">
            <HTML><BODY>
                  <P><B>
                        <xsl:for-each select="ss:Cell">
                              <xsl:value-of select="ss:Data"/>
                        </xsl:for-each>
                  </B></P>
            </BODY></HTML>            
      </xsl:template>
</xsl:stylesheet>       


The xml file is (Sorry if it is a bit long):

<?xml version="1.0"?>
<ss:Workbook xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <x:ExcelWorkbook>  <x:ProtectStructure>False</x:ProtectStructure>  <x:ActiveSheet>0</x:ActiveSheet> </x:ExcelWorkbook> <ss:Styles>  <ss:Style ss:ID="Default">   <ss:Alignment ss:Horizontal="Automatic" ss:Rotate="0.0" ss:Vertical="Bottom"    ss:ReadingOrder="Context"/>   <ss:Borders>   </ss:Borders>   <ss:Font ss:FontName="Arial" ss:Size="10" ss:Color="Automatic" ss:Bold="0"    ss:Italic="0" ss:Underline="None"/>   <ss:Interior ss:Color="Automatic" ss:Pattern="None"/>   <ss:NumberFormat ss:Format="General"/>   <ss:Protection ss:Protected="1"/>  </ss:Style>  <ss:Style ss:ID="wc0B870D30">   <ss:Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>   <ss:Font ss:Color="#FFFFFF" ss:Bold="1"/>   <ss:Interior ss:Color="#3366FF" ss:Pattern="Solid"/>  </ss:Style>  <ss:Style ss:ID="wcCC980D30">   <ss:Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>   <ss:Font ss:Color="#FFFFFF" ss:Bold="1"/>   <ss:Interior ss:Color="#FF0000" ss:Pattern="Solid"/>  </ss:Style>  <ss:Style ss:ID="wc8EA80D30">   <ss:Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>   <ss:Font/>   <ss:Interior ss:Color="#00CCFF" ss:Pattern="Solid"/>  </ss:Style>  <ss:Style ss:ID="wc4DB80D30">   <ss:Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>   <ss:Font/>   <ss:Interior ss:Color="#FFCC00" ss:Pattern="Solid"/>  </ss:Style>  <ss:Style ss:ID="wc0CC80D30">   <ss:Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>   <ss:Font/>   <ss:Interior ss:Color="#33CCCC" ss:Pattern="Solid"/>  </ss:Style>  <ss:Style ss:ID="wcC6770D30">   <ss:Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>   <ss:Font/>   <ss:Interior/>  </ss:Style> </ss:Styles> <c:ComponentOptions>  <c:Label>   <c:Caption>Feuille de calcul Microsoft Office</c:Caption>  </c:Label>  <c:MaxHeight>80%</c:MaxHeight>  <c:MaxWidth>80%</c:MaxWidth>  <c:NextSheetNumber>1</c:NextSheetNumber> </c:ComponentOptions> <x:WorkbookOptions>  <c:OWCVersion>10.0.0.2621         </c:OWCVersion>  <x:Height>11430</x:Height>  <x:Width>18627</x:Width> </x:WorkbookOptions> <ss:Names>  <ss:NamedRange ss:Name="CustomerID" ss:RefersTo="=Test!R2C2"/>  <ss:NamedRange ss:Name="EmployeeID" ss:RefersTo="=Test!R2C3"/>  <ss:NamedRange ss:Name="OrderID" ss:RefersTo="=Test!R2C1"/>  <ss:NamedRange ss:Name="ShipName" ss:RefersTo="=Test!R2C4"/> </ss:Names> <ss:Worksheet ss:Name="Test">  <x:WorksheetOptions>   <x:Selected/>   <x:DoNotDisplayGridlines/>   <x:ViewableRange>R1:R262144</x:ViewableRange>   <x:Selection>R1C1</x:Selection>   <x:TopRowVisible>0</x:TopRowVisible>   <x:LeftColumnVisible>0</x:LeftColumnVisible>   <x:ProtectContents>False</x:ProtectContents>  </x:WorksheetOptions>  <c:WorksheetOptions>  </c:WorksheetOptions>  <ss:Table ss:ExpandedColumnCount="4" ss:ExpandedRowCount="20"   ss:DefaultColumnWidth="60.0" ss:DefaultRowHeight="12.75">   <ss:Column ss:Width="82.5" ss:AutoFitWidth="0" ss:StyleID="wcC6770D30"/>   <ss:Column ss:Width="114.75" ss:AutoFitWidth="0" ss:StyleID="wcC6770D30"/>   <ss:Column ss:Width="105.75" ss:AutoFitWidth="0" ss:StyleID="wcC6770D30"/>   <ss:Column ss:Width="188.25" ss:AutoFitWidth="0" ss:StyleID="wcC6770D30"/>   <ss:Row>    <ss:Cell ss:StyleID="wc0B870D30">     <ss:Data ss:Type="String">Order ID</ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wcCC980D30">     <ss:Data ss:Type="String">Customer ID </ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wc0B870D30">     <ss:Data ss:Type="String">Employee ID </ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wcCC980D30">     <ss:Data ss:Type="String">Ship Name</ss:Data>    </ss:Cell>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30">     <ss:Data ss:Type="Number">10248</ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wc4DB80D30">     <ss:Data ss:Type="String">VINET</ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wc0CC80D30">     <ss:Data ss:Type="Number">5</ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wc4DB80D30">     <ss:Data ss:Type="String">Vins et alcools Chevalier</ss:Data>    </ss:Cell>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30">     <ss:Data ss:Type="Number">10248</ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wc4DB80D30">     <ss:Data ss:Type="String">VINET</ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wc0CC80D30">     <ss:Data ss:Type="Number">5</ss:Data>    </ss:Cell>    <ss:Cell ss:StyleID="wc4DB80D30">     <ss:Data ss:Type="String">Vins et alcools Chevalier</ss:Data>    </ss:Cell>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>   <ss:Row>    <ss:Cell ss:StyleID="wc8EA80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>    <ss:Cell ss:StyleID="wc0CC80D30"/>    <ss:Cell ss:StyleID="wc4DB80D30"/>   </ss:Row>  </ss:Table> </ss:Worksheet>  <o:DocumentProperties>   <o:Author>Rishi Raj TAPSEE</o:Author>   <o:LastAuthor>Rishi Raj TAPSEE</o:LastAuthor>   <o:Created>2004-09-10T13:28:46Z</o:Created>   <o:Company>IROISE</o:Company>   <o:Version>10.3501</o:Version>  </o:DocumentProperties>  <o:OfficeDocumentSettings>   <o:DownloadComponents/>   <o:LocationOfComponents HRef="file:///\\Iroise-3\NEW%20(D)\"/>  </o:OfficeDocumentSettings></ss:Workbook>
0
Comment
Question by:rrishi
3 Comments
 
LVL 19

Accepted Solution

by:
ramazanyich earned 125 total points
ID: 12101185
add following templates to your xsl:
     <xsl:template match="c:*"/>
     <xsl:template match="o:*"/>

By default if there is no templates defined per namespace then  XSLT processor will execute default template which will retrurn element values.
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 12108659
Either that, or avoid using stuff like:

          <xsl:apply-templates/>          
 
and instead select only those nodes you're interested in:

          <xsl:apply-templates select="ss:Table/ss:Row"/>

Regards,
Mike Sharp
0
 

Author Comment

by:rrishi
ID: 12109212
Thanks a lot!
I have tried both of them, and both are working properly.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with MSXML and Visual Studio 2013 1 50
XML filtering Windows Event Viewer 10 63
How to use xmlReader and idatareader  ? 4 57
Macro to import XML in Access 2013 2 50
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question