Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Multiple group using Muenchian Method [modified]

Multiple group using Muenchian Method [modified]

Scheduled Pinned Locked Moved XML / XSL
xmlquestion
3 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ONeil Tomlinson
    wrote on last edited by
    #1

    I have the following input XML. I want to group all unique Code/ID combination.

    <List>
    <Section>
    <Code>AA</Code>
    <ID>11</ID>
    <Section>
    <Section>
    <Code>AA</Code>
    <ID>11</ID>
    <Section>
    <Section>
    <Code>CC</Code>
    <ID>11</ID>
    <Section>
    <Section>
    <Code>AA</Code>
    <ID>22</ID>
    <Section>
    <Section>
    <Code>AA</Code>
    <ID>11</ID>
    <Section>
    <List>

    So result should be as shown below.

    <Code>AA</Code>
    <ID>11</ID>

    <Code>CC</Code>
    <ID>11</ID>

    <Code>AA</Code>
    <ID>22</ID>

    Im using the Muenchian Method. Currely my XSL (below) is grouping by Code (and not Code/ID combination)

    How do i get this to use a Code/ID combination? I tried nested for-each loop but no luck. Thanks

    modified on Tuesday, February 23, 2010 11:40 AM

    S 1 Reply Last reply
    0
    • O ONeil Tomlinson

      I have the following input XML. I want to group all unique Code/ID combination.

      <List>
      <Section>
      <Code>AA</Code>
      <ID>11</ID>
      <Section>
      <Section>
      <Code>AA</Code>
      <ID>11</ID>
      <Section>
      <Section>
      <Code>CC</Code>
      <ID>11</ID>
      <Section>
      <Section>
      <Code>AA</Code>
      <ID>22</ID>
      <Section>
      <Section>
      <Code>AA</Code>
      <ID>11</ID>
      <Section>
      <List>

      So result should be as shown below.

      <Code>AA</Code>
      <ID>11</ID>

      <Code>CC</Code>
      <ID>11</ID>

      <Code>AA</Code>
      <ID>22</ID>

      Im using the Muenchian Method. Currely my XSL (below) is grouping by Code (and not Code/ID combination)

      How do i get this to use a Code/ID combination? I tried nested for-each loop but no luck. Thanks

      modified on Tuesday, February 23, 2010 11:40 AM

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Firstly, your key needs to have an expression which reflects what you want to retrieve:

      <xsl:key name="CCids" match="/List/Section" use="concat(Code,'|',ID)"/>

      And then you need to use that same expression when accessing items referenced by the key. Oh - and in addition, I would suggest not using a for loop - it's not idiomatic XSL. Here's the file I'd use:

      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var" version="1.0" xmlns:ns0="http://A4C.Interface.HRP.Payroll.Schemas">
      <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" encoding="utf-8"/>

      <xsl:key name="CCids" match="/List/Section" use="concat(Code,'|',ID)"/>

      <xsl:template match="/">
      ns0:List
      <xsl:apply-templates select="/List/Section [generate-id(.)=generate-id(key('CCids',concat(Code,'|',ID)))]"/>
      </ns0:List>
      </xsl:template>

      <xsl:template match="Section">
      <Section>
      <Code>
      <xsl:value-of select="Code/text()" />
      </Code>
      <ID>
      <xsl:value-of select="ID/text()" />
      </ID>
      </Section>
      </xsl:template>
      </xsl:stylesheet>

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

      O 1 Reply Last reply
      0
      • S Stuart Dootson

        Firstly, your key needs to have an expression which reflects what you want to retrieve:

        <xsl:key name="CCids" match="/List/Section" use="concat(Code,'|',ID)"/>

        And then you need to use that same expression when accessing items referenced by the key. Oh - and in addition, I would suggest not using a for loop - it's not idiomatic XSL. Here's the file I'd use:

        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var" version="1.0" xmlns:ns0="http://A4C.Interface.HRP.Payroll.Schemas">
        <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" encoding="utf-8"/>

        <xsl:key name="CCids" match="/List/Section" use="concat(Code,'|',ID)"/>

        <xsl:template match="/">
        ns0:List
        <xsl:apply-templates select="/List/Section [generate-id(.)=generate-id(key('CCids',concat(Code,'|',ID)))]"/>
        </ns0:List>
        </xsl:template>

        <xsl:template match="Section">
        <Section>
        <Code>
        <xsl:value-of select="Code/text()" />
        </Code>
        <ID>
        <xsl:value-of select="ID/text()" />
        </ID>
        </Section>
        </xsl:template>
        </xsl:stylesheet>

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

        O Offline
        O Offline
        ONeil Tomlinson
        wrote on last edited by
        #3

        Thanks..Really helpful ;)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups