Solved

XSLT retaining undesired text

Posted on 2004-09-20
3
452 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
Deserialize xml file, importing data stops when using DoubleClick! 1 62
Getting attribute Values using xslt 4 47
XML namaspace 2 50
XML XSLT If loop 4 26
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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