p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: XSLT Programmer's Reference, 2nd Edition (http://p2p.wrox.com/forumdisplay.php?f=52)
-   -   XPATH Help, Please- Excel XML Workbook (http://p2p.wrox.com/showthread.php?t=48428)

jftaylor September 28th, 2006 04:06 PM

XPATH Help, Please- Excel XML Workbook
Sorry for the length... I need XPATH help.

I'm trying to extract some data from an Excel workbook saved as an XML spreadsheet.

Here's a very small sample file:

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>

  <NamedRange ss:Name="Low_Right" ss:RefersTo="=Sheet1!R2C2"/>
  <NamedRange ss:Name="Top_Left" ss:RefersTo="=Sheet1!R1C1"/>
 <Worksheet ss:Name="Sheet1">
  <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1"
    <Cell><Data ss:Type="String">topLeft</Data><NamedCell ss:Name="Top_Left"/></Cell>
    <Cell ss:Index="2"><Data ss:Type="String">LowRight</Data><NamedCell
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">

I'm looking for a way to capture all the Cell nodes that have data. I've tried "//Cell" in the select parameter in for-each, fully specifying the path, and a number of different templates matches, but can't nail it down. Specifically, I also want to capture Data element values based on the sibling "NamedCell" element.

It's possible that the parsing tool is not capable (MSXSL.exe)

Any help will be greatly appreciated!!!

mhkay September 28th, 2006 04:37 PM

//Cell won't select anything, because the Cell elements are in namespace urn:schemas-microsoft-com:office:spreadsheet. You need to select them as //ss:Cell, with the prefix ss bound to "urn:schemas-microsoft-com:office:spreadsheet".

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

jftaylor September 28th, 2006 08:47 PM

Thanks for the fast answer Michael, Multiple namespaces are not something I've dealt with before. I'll give that a try...

All times are GMT -4. The time now is 01:58 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.