Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Frederik T 242 posts 373 karma points
    Feb 29, 2012 @ 13:52
    Frederik T
    0

    First match in a for-each loop, but with a twist

    The title might be misleading but i couldnt come up with something more descriptive.

    Anyway i will try and explain my problem as good as i can:

    I retrieve data from a xml coming from a webservice, which i have an xslt iterate through and build up the page with using the information stored in the xml.

    Each node in the xml represents a "job" in a job listing. Each node can have more than one of the same childnode (i hope i use the correct words, remember i am talking about xml right now).
    For example, a job can have several job regions, so if i have a for-each that prints out its job regions it prints out all of them, so far so good. Problem is, on some occasions the same region can be dublicated in the xml file having the same region printed out multiple times.

    This is where i need some help.

    Here is a simplified version of the xml im using:

    <Job> (there's several of these in each xml document)
    <Regions>
     <JobRegion> (Each "Job" can have more than one)
      <RegionID>123</RegionID>
      <Name>Some Region</Name>
     </JobRegion>
    </Regions>
    </Job>

    So if there is for example one "JobRegion" with id 123, and two with ID 456, how can i get just one of each?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 29, 2012 @ 18:12
    Jan Skovgaard
    1

    Hi Frederik

    If you will need to do some grouping in XSLT using the muenchian method to achieve the above I think.

    You can see an example of muenchian grouping done by Chriztian in this post based on umbraco generated XML: http://our.umbraco.org/forum/developers/xslt/17142-Simple-Muenchian-grouping#comment64260

    Tommy poulsen has written a bit about it here as well: http://blackpoint.dk/umbraco-workbench/xslt/grouping--distinct-values.aspx?p=3

    Hope this helps.

    /Jan

  • Frederik T 242 posts 373 karma points
    Mar 07, 2012 @ 10:39
    Frederik T
    0

    thank you for your reply, i tried looking through the examples but i find them somewhat difficult to understand, because i think mine is more simple. Its not umbraco nodes or anything, just a regular xml document.

    <ArrayOfJob>
    <Job> (there's several of these in each xml document)
    ....other information that a job can contain....
    <Regions>
      <JobRegion> (Each "Job" can have more than one of these)
      <RegionID>123</RegionID>
      <Name>Some Region</Name>
      </JobRegion>
    </Regions>
    </Job>
    </ArrayOfJob>

    I only need one of each of the "JobRegion" if there's duplicates.

Please Sign in or register to post replies

Write your reply to:

Draft