Solved

Call template when values match

Posted on 2013-01-04
3
209 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 500 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

687 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