Subject: RE: [xsl] please help. newbie needs help!! From: "M. David Peterson" <m.david@xxxxxxxxxx> Date: Tue, 11 May 2004 05:10:35 -0600 |
Thanks for catching this Jeni! If I would have actually built a test template and processed this like I normally do before sending out something to the list I would have caught this, smacked myself upside the headed, corrected it, tested it again, and sent it out once everything had processed as expected. Just goes to show how the simplest of things can make such a HUGE difference. Doing the above would have also caught the fact that I didn't put a quote at the end of my statement and should have used single quotes instead of double within the selection statements. Jeremy, my apologies to you if I frustrated you more than helped you. Thanks again for the catch Jeni! I owe you one ;) Best regards, <M:D/> -----Original Message----- From: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx] Sent: Tuesday, May 11, 2004 4:57 AM To: Jeremy Allen Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] please help. newbie needs help!! 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] please help. newbie needs, Jeni Tennison | Thread | Re: [xsl] problem SOLVED: recursive, poppe chris |
Re: [xsl] please help. newbie needs, Jeni Tennison | Date | RE: [xsl] Handling Cross References, Jarno.Elovirta |
Month |