Solved

Call template when values match

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

739 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