?
Solved

Call template when values match

Posted on 2013-01-04
3
Medium Priority
?
211 Views
Last Modified: 2013-01-04
i have the following xml input

<RS>
      <SAvailRQ>
            <Code>AL</Code>
            <FNum>131</FNum>
      </SAvailRQ>
<SMapRS>
  <SMapResponses>
      <SMapResponse>
            <SegInfo FNum="131">
            <Departure LocationCode="MIA"/>
            <Arrival LocationCode="LAX"/>
            <Marketing Code="AL"/>
            </SegInfo>
      </SMapResponse>
      <SMapResponse>
            <SegInfo FNum="118">
            <Departure LocationCode="LAX"/>
            <Arrival LocationCode="MIA"/>
            <Marketing Code="AL"/>
            </SegInfo>      
      </SMapResponse>      
   </SMapResponses>
</SMapRS>      
</RS>      

I need logic such that if RS/SAvailRQ/FNum matches that found in RS/SMapRS/SMapResponses/SMapResponse/SegInfo/@FNum
to call a template to build an Info node on that match only.

Currently, I have the following
    <xsl:apply-templates select="SMapResponses/SMapResponse/SegInfo"/>
but this loops twice (bc there are 2 SegInfo), I do not want that. I just want it to go into this template for the matching record(s) and then process data for that matching record only.

So how do I apply a for-each statement that will find matching FNum in SAvailRQ with that in SMapResponse and have that template called for that instance(s) only?


basically a filter.
0
Comment
Question by:badtz7229
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 38744876
<xsl:variable name="this-fnum" select="ancestor::RS/SAvailRQ/FNum"/>
<xsl:apply-templates select="SMapResponses/SMapResponse/SegInfo[@FNum = $this-fnum]"/>
0
 

Author Closing Comment

by:badtz7229
ID: 38744945
yes, that worked successfully.

if possible, can you please explain how the ancestor feature works in this case?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 38744962
well, since I found this in the selct of your apply-templates
SMapResponses/SMapResponse/SegInfo,
I assumed your current context was SMapRS,
that means you have to go up and back down again to get the FNum value
ancestor:: is theaxis walking up the tree
so ancestor::RS is jumping back up to the root of the XML
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question