Solved

XSLT retaining undesired text

Posted on 2004-09-20
3
445 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# advanced xml like string split - Help needed 15 73
Extract data from xml in c# 8 51
CRM 2011 Ribbon Workbench vs RibbonDiffXml 44 252
XML & .net 5 40
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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now