Solved

XSLT retaining undesired text

Posted on 2004-09-20
3
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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