Solved

XSLT retaining undesired text

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
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, …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

16 Experts available now in Live!

Get 1:1 Help Now