Solved

Call template when values match

Posted on 2013-01-04
3
204 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to create a tile layout 1 20
How do I bind the results to a grid 3 24
Menu Inconsistent 3 22
Create XML 5 35
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
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.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now