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

Re: Selecting Specific Elements Regardless of Namespac

Subject: Re: Selecting Specific Elements Regardless of Namespace
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 09 May 2002 15:38:24 -0400
vegetables.com
Lindy,

What you're saying is confusing since the term "namespace" does not match the example you gave.

//fruit/apples/grannysmith/apple does not match an apple element in a fruit namespace. A fruit element is an ancestor (here, great-grandparent) of an apple element, but they are both in the same namespace (here, whatever namespace has no prefix).

If your source has something like

<fruit xmlns="www.fruit.com">
  <apples>
    <grannysmith>
      <apple>...</apple>
    </grannysmith>
  </apples>
</fruit>

I guess you could say the apple is in the fruit namespace, whereas in

<fruit xmlns="www.vegetables.com">
  <apples>
    <grannysmith>
      <apple>...</apple>
    </grannysmith>
  </apples>
</fruit>

it's not. Is this what you mean?

If so, you can distinguish by setting up distinctive namespace bindings in your stylesheet to distinguish between the fruit and vegetables namespaces. E.g.

<xsl:template xmlns:fruit="www.fruit.com"
              xmlns:veggies="www.vegetables.com">
  <xsl:value-of select="//fruit:fruit"/>
</xsl:template>

gets you the value of the first fruit element in the www.fruit.com namespace.

To get the first fruit element regardless of its namespace, the trick you first had, //*[local-name()='fruit'] is something of a hack, but serviceable. Since XPath had no expression to say "in any namespace", things do get tricky here and the hack is justifiable.

To get a fruit element regardless of a namespace but making sure it's a child of a jonathan, also regardless of what namespace the jonathan is in, you could do

//*[local-name()='jonathan']/*[local-name()='apple']

But that's pretty unfortunate. As you can see, the namespace mechanism isn't really designed to support type-identity of elements across namespaces; in fact, just the opposite.

Is that closer?

Cheers,
Wendell

At 03:13 PM 5/9/2002, you wrote:

That isn't quite the answer to my question. I am needing to do this regardless of the namespace. Let me go into a little more detail

I am in an xsl sheet that creates html. I need to know the value of the grannysmith/apple node using a xsl:value-of statment pathed directly to that node. This xml I have however is in a fruit namespace and I don't want to know that I am in the fruit namespace.

Thanks

Lindy


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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.