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

Re: why dosen't it read the xml info?

Subject: Re: why dosen't it read the xml info?
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Mon, 05 Jun 2000 18:24:12 +0100
xml data search
Yonit,

First, you should tidy up your code so that it is well-formed (i.e. giving
an opening <a> tag just after the xsl:for-each and adding a closing </font>
tag).  These might just be copying errors, though, particularly as I'd have
thought you'd get a lot sterner warnings if you had these in your real
stylesheet!

The source of your problem, though, is your use of namespaces.  Within your
source XML, you specify:

  <search xmlns="urn:schemas-microsoft-com:xml-data"
          xmlns:dt="urn:schemas-microsoft-com:datatypes">
  ...
  </search>

This states that the default namespace (i.e. the namespace for elements for
which no namespace is explicitly given) is
'urn:schemas-microsoft-com:xml-data'.  That means that the 'search'
element, and all its children, are within that namespace.

Within your stylesheet, though, you haven't specified those namespaces.
The stylesheet will look for a 'search' element with a null namespace, of
which there aren't any in your document.  There are three things that you
can do to make it work.  

Firstly, you can specify a named namespace within the stylesheet, and
specify that the elements you're searching for are within that namespace,
e.g.:

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns:data="urn:schemas-microsoft-com:xml-data">

  <xsl:template match="/">
    <html>
    <body>
      <xsl:apply-templates select="data:search/data:type" />
      <xsl:value-of select="data:search/data:type" />
      <xsl:value-of select="data:search/data:auctions" /> sales
      ...
    </body>
    </html>
  </xsl:template>

  </xsl:stylesheet>

Secondly, you can specify that as the default namespace, but make sure that
all the html elements that you use are within an HTML namespace.  Then you
can use an xsl:namespace-alias element to make sure that your HTML elements
aren't namespaced within your output:

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns:html="http://www.w3.org/1999/xhtml"
                  xmlns="urn:schemas-microsoft-com:xml-data">

  <xsl:namespace-alias stylesheet-prefix="html" result-prefix="#default" />

  <xsl:template match="/">
    <html:html>
    <html:body>
      <xsl:apply-templates select="search/type" />
      <xsl:value-of select="search/type" />
      <xsl:value-of select="search/auctions" /> sales
      ...
    </html:body>
    </html:html>
  </xsl:template>

  </xsl:stylesheet>

Finally, you can think again about whether you need to specify namespaces
in your source document in the first place.

I hope that helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email
jeni.tennison@xxxxxxxxxxxxxxxx



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.