More XPath Fun

In Jon's post he dug around and found that he could use a query to pull a table out of the Syncato database. He used this query http://www.xmldatabases.org/WK/blog/item//table[contains(.,'Annie Lennox')]. This of course works for any markup added to the database and provides a very solid incentive to add richer markup to your posts. Because of this I wanted to highlight another cool thing you can do with Syncato. You can use XPath directly in your posts to pull in other content from the database.

For instance we can use Jon's query to pull in the table he was talking about.

ArtistSongAlbumPlay Count
MetallicaFranticSt. Anger12
Massive AttackAntistar100th Window11
Massive AttackButterfly Caught100th Window11
Massive AttackEverywhen100th Window11
Massive AttackFuture Proof100th Window11
Massive AttackName Taken100th Window11
Massive AttackHymn Of The Big Wheel (OriginHymn Of The Big Wheel11
MetallicaDirty WindowSt. Anger11
MetallicaMy WorldSt. Anger11
Annie LennoxA Thousand Beautiful ThingsBare10
Annie LennoxBitter PillBare10
Annie LennoxErasedBare10
EvanescenceBring Me To Life (Feat. PaulFallen10
Massive AttackPrayer For England100th Window10
Massive AttackSmall Time Shot Away100th Window10
Massive AttackSpecial Cases100th Window10
Massive AttackWhat Your Soul Sings100th Window10
Massive AttackAny Love (Larry Heard Mix)Hymn Of The Big Wheel10
Massive AttackHome Of The WhaleHymn Of The Big Wheel10
Massive AttackHymn Of The Big Wheel (NelleeHymn Of The Big Wheel10
Annie LennoxHonestlyBare9
Annie LennoxLonelinessBare9
Annie LennoxOh God (Prayer)Bare9
EvanescenceEverybody`s FoolFallen9
EvanescenceGoing UnderFallen9
Annie LennoxA Thousand Beautiful ThingsBare10
Annie LennoxBitter PillBare10
Annie LennoxErasedBare10
Annie LennoxHonestlyBare9
Annie LennoxLonelinessBare9
Annie LennoxOh God (Prayer)Bare9

The markup to do this is.

<xpath-query>/item//table[contains(.,'Annie Lennox')]</xpath-query>

We can also do cool things like just pulling in the particular rows that Annie Lennox is mentioned in.

Annie LennoxA Thousand Beautiful ThingsBare10
Annie LennoxBitter PillBare10
Annie LennoxErasedBare10
Annie LennoxHonestlyBare9
Annie LennoxLonelinessBare9
Annie LennoxOh God (Prayer)Bare9

To do that you just have to fill in the missing pieces of HTML in your post.

<table>
<xpath-query>/item//table/tr[contains(.,'Annie Lennox')]</xpath-query>
</table>
Loads of fun I tell ya.

Posted by Kimbro Staken

Wednesday Sep 17, 2003 at 3:41 AM
Recommended Sites