This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Selecting Specific Elements Regardless of Namespace


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@mulberrytech.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]