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

Re: node extraction from on the basis of an element

Subject: Re: node extraction from on the basis of an element
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 17 Aug 2001 09:30:56 +0100
xml node travel
Hi Sunil,

> I have a block of XML where one element my have more then one type
> of data as "<type>" element may have either data like profession or
> topic or specialty. I want to extract only those node which have a
> type profession.
>
> <cc:keywords>
>         <cc:keyword>
>                 <type>profession</type>
>                 <ID>1071</ID>
>                 <langstring lang="en_US">Physician</langstring>
>         </cc:keyword>
>         <cc:keyword>
>                 <type>specialty</type>
>                 <ID>102</ID>
>                 <langstring lang="en_US">CLINICAL</langstring>
>         </cc:keyword>
>         <cc:keyword>
>                 <type>specialty</type>
>                 <ID>115</ID>
>                 <langstring lang="en_US">INFECTIOUS DISEASE</langstring>
>         </cc:keyword>
> </cc:keywords>

This piece of XML is well-formed, but it doesn't conform to the
namespaces Recommendation because it doesn't have a namespace
declaration for the 'cc' prefix, so an XSLT processor won't be able to
use it. Assuming it actually looks like:

<cc:keywords xmlns:cc="http://www.cecity.com/xml/cecity_classification">
...
</cc:keywords>

I'm also going to assume that you don't have a default namespace
declaration in your source XML document. If you do, then the answer is
different.

You need to declare the
http://www.cecity.com/xml/cecity_classification namespace in your
stylesheet:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:cc="http://www.cecity.com/xml/cecity_classification">
...
</xsl:stylesheet>

then you need to start from the root node:

  /

travel down step by step to the cc:keyword elements:

 /cc:keywords/cc:keyword

and use a predicate to identify those whose child type element (in no
namespace) is equal to the string 'profession':

  /cc:keywords/cc:keyword[type = 'profession']

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.