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
|
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
|