Solved

Call template when values match

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

830 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