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

RE: Suggested guidelines for using local types. (was Re: Enlightenment v

  • From: "Fuchs, Matthew" <matthew.fuchs@c...>
  • To: 'Jonathan Borden' <jborden@m...>, xml-dev@l...
  • Date: Fri, 31 Aug 2001 15:29:45 -0700

match local name
Well...

As I thought Rick made abundantly clear, if you put globals and locals in
the same namespace, then you need to worry about aliasing issues.  So,
suppose (as in this case) there is a global element "name" and a
(structurally different) local element "name" defined inside the global
element "person".  Now I want to write a template to handle the global
"name", and a template to handle the global element "person" (I include the
default template for a reason) and let the locally scoped name be handled by
the default template:

<template match="*|/">
  ...some default behavior...
</template>
<template match="x:name">...
<template match="x:person">
  ...
  <apply-templates/>
  ...
</template>

What happens to the document with the following fragment?

  <x:name>...</x:name>
  <x:person><x:name>...</x:name></x:person>

Well, the first x:name is appropriately handed to the global template.  Then
x:person is handed to the right template.  Then x:name is handed to ... the
_wrong_ template.  It matches the template intended for the global x:name -
and the script promptly crashes.  The only way to make this work is to
explicitly add a template for the scoped "name":

<template match="*|/">
  ...some default behavior...
</template>
<template match="x:name">...
<template match="x:person/x:name">...default (potentially complex)
behavior...</template>
<template match="x:person">
  ...
  <apply-templates/>
  ...
</template>

And this must be systematically done for _every_ local name if you want to
escape the fragility Rick describes, even if you wnat them to have the
default handling.  Not very robust.

Now suppose the "name" local to "person" is not in a namespace.  Then the
fragment is:

<x:name>...</x:name>
<x:person><name>...</name></x:person>

and we run that against the first script:

<template match="*|/">
  ...some default behavior...
</template>
<template match="x:name">...
<template match="x:person">
  ...
  <apply-templates/>
  ...
</template>

The global "name" now matches against the right template.  The "person"
template matches against the right template.  And the _local_ "name" doesn't
match the template for the global "name" because (tada!) it's not in the
right namespace.  Therefore it defaults to matching the default template -
just the behavior Rick wants (I think).

Suppose, in addition, I want to add a template for the local name.  What
should the template be?  Well, since it's not in a namespace, and I don't
want it to also match the local "name" inside some other element might have
a different structure, it would have to be:

<template match="x:person/name">...

If I wanted to save characters, I'd use YACC.

Matthew

> -----Original Message-----
> From: Jonathan Borden [mailto:jborden@m...]
> Sent: Friday, August 31, 2001 2:49 PM
> To: Fuchs, Matthew; 'Rick Jelliffe'; xml-dev@l...
> Subject: Re: Suggested guidelines for using local types. (was Re:
> Enlightenment via avoiding the T-word)
> 
> 
> Fuchs, Matthew wrote:
> >
> > In other words, if one follows the best practice of:
> > 1) always using a targetNamespace for your schema
> > 2) always making local names unqualified
> 
> what is the advantage of this? why not simply qualify local 
> names with the
> targetNamespace?
> 
> i.e. the patterns
> 
> <template match="x:person/name"> ...
> 
> vs.
> 
> <template match="x:/person/x:name"> ...
> 
> is it that you wish to save writing the prefixed qname in the XPath
> expression? yet the small savings in characters here is more 
> than offset by
> the difficulty reading the source document.
> 
> In Rick's terminology I vote for QC + QL.
> 
> Jonathan
> 
> 

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.