[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: please help. newbie needs help!!

Subject: Re: please help. newbie needs help!!
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 11 May 2004 11:56:59 +0100
ss worksheet
Hi Jeremy,

> I need an xpath expression for getting data from this xml, for
> example what expression would I use to get the string "THE WATERSHED
> GROUP, LLC"?

M.David Peterson has given you some good ideas about how to get this
string, but he missed one important feature of the XML that you're
working with, namely that it's using a default namespace. This is
something that trips people up all the time, so perhaps it's something
you're having problems with too...

Your data uses default namespaces, with different defaults in
different areas. The default that's declared at the top level of the
XML, on the <Workbook> element, is declared with:

  xmlns="urn:schemas-microsoft-com:office:spreadsheet"

This namespace declaration is in scope for most of the elements, with
the exceptions of the <DocumentProperties> element and its descendants
(which have a default namespace of
urn:schemas-microsoft-com:office:office) and the <ExcelWorkbook>
element and its descendants (which have a default namespace of
urn:schemas-microsoft-com:office:excel). So most of the elements in
your XML document are in the namespace
urn:schemas-microsoft-com:office:spreadsheet.

To refer to elements in a namespace from within an XSLT stylesheet,
you need to do two things:

  - declare the namespace, associating it with a prefix, at the very
    top of the stylesheet

  - use the prefix that you've associated with the namespace whenever
    you refer to an element in that namespace

So, to get to the <Data> element that you're interested in, you need
to declare the urn:schemas-microsoft-com:office:spreadsheet namespace,
like so:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
...
</xsl:stylesheet>

And the names of the elements in the path to the relevant <Data>
element need to be prefixed as follows:

  /ss:Workbook
    /ss:Worksheet
      /ss:Table
        /ss:Row[@ss:Index = '2']
          /ss:Cell
            /ss:Data

I've arranged this path on several lines so that you can see how its
structure matches the structure of your document -- you can get rid of
the whitespace if you want.

Note also that there are many ways of selecting the <Row> element that
you're after: the one above chooses the <Row> element whose ss:Index
attribute has the value '2', but you could just use a positional
predicate (ss:Row[2]) to choose the second row in the table.

If you *don't* use a prefix on the element names, then the XSLT
processor will think that you're trying to select elements in no
namespace (no matter what the default namespace in the stylesheet is).
Since there aren't any such in your document, it won't find any, and
you'll get nothing out.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.