[html5] microdata itemref

Ian Hickson ian at hixie.ch
Mon Dec 10 12:57:10 PST 2012


On Mon, 10 Dec 2012, Brian Tremblay wrote:
> On 12/10/12 11:07 AM, Ian Hickson wrote:
> > On Mon, 10 Dec 2012, Brian Tremblay wrote:
> > > 
> > > What I'm trying to do is associate "Napa Valley" in the <p> element with
> > > the winery in the header, as that winery's addressRegion.
> > 
> > If you mean the text, you need some additional markup because the <a>
> > element in microdata only ever represents its URL, so e.g.:
> > 
> >    <article itemscope itemtype="http://schema.org/FoodEvent">
> >     <header>
> >       <h1 itemprop="name">Franciscan Estate tasting</h1>
> > 
> >       hosted by
> >       <div itemprop="performer" itemscope
> > itemtype="http://schema.org/Person">
> >         <span itemprop="name">J. Kounellas</span>,
> >         <span itemprop="worksFor" itemscope
> > itemtype="http://schema.org/Winery"
> >               itemref="wineryLocation">
> >           <span itemprop="name">Franciscan Estate Winery</span>
> >         </span>
> >       </div>
> >     </header>
> > 
> >     <p itemprop="description">Join us for a special wine event featuring
> >     <a href="http://en.wikipedia.org/wiki/Napa_Valley_AVA"
> >      ><span id="wineryLocation" itemprop="addressRegion">Napa
> >      Valley</span></a>'s Franciscan Estate Winery.
> >     </p>
> >    </article>
> 
> That generates an error from Google's rich snippet testing tool:
> 
> "Warning: Page contains property "addressregion" which is not part of 
> the schema."

Ah, good point, I didn't think of that. Fundamentally the issue there is 
that you have data from different items overlapping; there's not much you 
can do about that.

The simplest, though unsatisfying, solution is just to use <meta>:

    <article itemscope itemtype="http://schema.org/FoodEvent">
     <header>
       <h1 itemprop="name">Franciscan Estate tasting</h1>
       hosted by
       <div itemprop="performer" itemscope itemtype="http://schema.org/Person">
         <span itemprop="name">J. Kounellas</span>,
         <span itemprop="worksFor" itemscope itemtype="http://schema.org/Winery">
           <span itemprop="name">Franciscan Estate Winery</span>
           <meta itemprop="addressRegion" content="Napa Valley">
         </span>
       </div>
     </header>
     <p itemprop="description">Join us for a special wine event featuring
     <a href="http://en.wikipedia.org/wiki/Napa_Valley_AVA">Napa
     Valley</a>'s Franciscan Estate Winery.</p>
    </article>

I don't think there's a good solution that doesn't involve duplication 
when a single element is a property for one item and contains a property 
for another; as it stands today there's no way to exclude a subtree from 
an item other than making it an item itself. If you wanted to do that, you 
could do something like this:

    <article itemscope itemtype="http://schema.org/FoodEvent">
     <header>
       <h1 itemprop="name">Franciscan Estate tasting</h1>
       hosted by
       <div itemprop="performer" itemscope itemtype="http://schema.org/Person">
         <span itemprop="name">J. Kounellas</span>,
         <span itemprop="worksFor" itemscope itemtype="http://schema.org/Winery"
               itemref="napa">
           <span itemprop="name">Franciscan Estate Winery</span>
         </span>
       </div>
     </header>
     <p itemprop="description">Join us for a special wine event featuring
     <a itemscope href="http://en.wikipedia.org/wiki/Napa_Valley_AVA"><span 
        itemprop="addressRegion" id="napa">Napa Valley</span></a>'s 
     Franciscan Estate Winery.</p>
    </article>

What this does is introduce an anonyous item which blocks out the 
addressRegion property from the outer FoodEvent item. It's a hack, 
certainly. It works, though, because anonymous items don't really mean 
much (they're just for private use by page authors), and it shouldn't 
interfere with any public use of the microdata (e.g. by schema.org 
processors and so on).

In the future we might introduce a way to explicitly exclude a subtree 
from an ancestor, if this is a common issue.


By the way, as far as I can tell addressRegion isn't a valid schema.org 
value for a Winery item. Looks like you need another item just for the 
addressRegion or something. This is quite the elaborate vocabulary. :-/

HTH,
-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the Help mailing list