Re: [xsl] xpath question

Subject: Re: [xsl] xpath question
From: xslt.new <xslt.new@xxxxxxxxx>
Date: Wed, 24 Jan 2007 09:53:30 -0600
Hello David;

Thank you for your reply. I am using xslt1.0

However are you sure you need to process all scene elements out of
sequence like this?

The reason for me to figure out if <scene> is located under <list1> or <list2> is because I would like to filter out data based on certain conditions on the <scene> tag.

So, if I have parameters set1 and set 2 on the style sheet set to
Yahoo and google, I want all elements which have Yahoo and google. If
at the <list1> level itself, this condition fails, then I do not want
to even check if this condition satisfies under <list2>. this is where
I was having difficulty with the xpath, because when I said .//scene,
it matches all <scene> elements under <list1> which includes <list2>
also. I do not want that to happen. How do I achieve this? I am
testing for these conditions under templates <list1> and  <list2>.


<list1> <text> <para> <scene> <set1></set1> <set2></set2> </scene> </para> </text> <list2> <text> <para> <scene> <set1></set1> <set2></set2>

 </scene>
</para>
</text>

<list2>
</list1>

<list1>
<text>
<para>
 <scene>
      <set1></set1>
      <set2></set2>
</scene>
</para>
</text>
 <list2>
<text>
<para>
 <scene>
      <set1></set1>
      <set2></set2>

 </scene>
</para>
</text>

<list2>
</list1>


On 1/24/07, David Carlisle <davidc@xxxxxxxxx> wrote:

I can't remember if you are using xslt2 or xslt1, a direct encoding of


> if I want to locate only the <scene>
> element under ALL<list1> elements in the whole XML input inside the
> <list1> template, and NOT the <scene> element under <list2>,

in xpath2 would be

.//scene except .//list2//scene

in xpath1 you could use

.//scene[not(ancestor::list2)]

(which doesn't mean quite the same thing in general but will select the
same things so long as list1 is never a descendent of list2.

However are you sure you need to process all scene elements out of
sequence like this?

more commonly in xslt you woul djust have a tempolate for scene elements

<xsl:tempate match="scene">...

and a higher priority template for scenes under list2


<xsl:tempate match="list2//scene">...


and so don't need to explictly select those scenes which are under list1
but not under list2, they automatically are matced by the first
template.

David

Please read the posting guidelines for this list which advise you not to
use subject lines such as  "xpath question" which could apply to most of
teh postings on this list.

Current Thread