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

Re: xpath question

Subject: Re: xpath question
From: xslt.new <xslt.new@xxxxxxxxx>
Date: Wed, 24 Jan 2007 10:22:30 -0600
Re:  xpath question
Hi David:

This is what I am trying to do. I have input XML file:

<list1>
<text>
<para>This has yahoo and google. This should be displayed in the
output if set1 and set2 are set to Yahoo and google on the style sheet
parameters.</para>
 <scene>
      <set1>Yahoo</set1>
      <set2>Google</set2>
</scene>

</text>
 <list2>
<text>
<para>This has Yahoo and MSN.This should not be displayed in the
output if set1 and set2 are set to Yahoo and google on the style sheet
parameters.</para>
 <scene>
      <set1>Yahoo</set1>
      <set2>MSN</set2>

</scene>

</text>

</list2>
</list1>

<list1>
<text>
<para>This has Yahoo and MSN. So condition checking should stop here. </para>
 <scene>
      <set1>Yahoo </set1>
      <set2>MSN</set2>
</scene>

</text>
 <list2>
<text>
<para>This should not be displayed in the output if set1 and set2 are
set to Yahoo and google on the style sheet parameters since <list1>
fails. </para>
 <scene>
      <set1>Yahoo</set1>
      <set2>Google</set2>

</scene>

</text>

</list2>
</list1>

So  if I have parameters set1 and set2 on the style sheet set to:
<xsl:param name="set1">Yahoo</xsl:param>
<xsl:param name="set2">Google</xsl:param>

Then desired output is:

This has yahoo and google. This should be displayed in the output if
set1 and set2 are set to Yahoo and google on the style sheet
parameters.

My XSLT for this:

<xsl:template match="list1">
	<xsl:choose>
<!-- I want to check if <list> indeed contains <scene> or not-->
		<xsl:when test=".//scene">
			<xsl:choose>
				<xsl:when test=".//scene/set1=$set1 and .//scene/set2=$set2">
					<li type="1">
						<xsl:value-of select="node()"/>
					</li>
				</xsl:when>
				<xsl:otherwise>
						
						</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
	</xsl:choose>
</xsl:template>

What is wrong with this approach? Is there any other way to approach
this problem?


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

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

that doesn't imply that you need to select them all in one xpath it's
far more common just to use templates to process iteratively.
You haven't really given enough descriptuon of your input, or any
description of your output so it's hard to offer concrete advice, but
something like

<xsl:template match="list1|list2">
  <xsl:if test="./text/para/scene[set1=$set1 and set2=$set2]">
    <xsl:apply-templates/>
</xsl:template>

which seems to do what you say you want (without answering the xpath
question in your first post in this thread).
If the list1 scene doesn't match teh condition, everything is skipped,
if it does meet the condition, eveything is processed, and teh scene for
list2 will be checked once that is processed.

David

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.