Solved

a simple xml-xslt transformation

Posted on 2011-02-13
3
395 Views
Last Modified: 2012-05-11
Sorry for the lameness of the question, but I need to figure this out fast.

I have this example xml:
<event>
        <Org_Name><![CDATA[Community Music Center]]>
        </Org_Name>
        <Venue_Name><![CDATA[Community Music Center]]>
        </Venue_Name>
        <Venue_address><![CDATA[544 Capp]]>
        </Venue_address>
        <Event_Phone><![CDATA[647-6015]]>
        </Event_Phone>
        <Org_Web><![CDATA[HTTP://www.sfcmc.org]]>
        </Org_Web>
        <Date_String><![CDATA[Mar 25]]>
        </Date_String>
        <Time_String><![CDATA[Sun at 4 pm]]>
        </Time_String>
        <Event_Name><![CDATA[Andrew Meyerson and Friends ]]>
        </Event_Name>
        <Event_Description><![CDATA[Andrew Meyerson and guest artists perform contemporary musical selections. ]]>
        </Event_Description>
        <Ticket_String><![CDATA[$10; $5 seniors & students]]>
        </Ticket_String>
    </event>
    <event>
        <Org_Name><![CDATA[Stanford Lively Arts]]>
        </Org_Name>
        <Venue_Name><![CDATA[Community School of Music and Arts]]>
        </Venue_Name>
        <Venue_address><![CDATA[230 San Antonio Circle]]>
        </Venue_address>
        <Event_Phone><![CDATA[650/725-ARTS]]>
        </Event_Phone>
        <Org_Web><![CDATA[HTTP://livelyarts.stanford.edu]]>
        </Org_Web>
        <Date_String><![CDATA[Mar 3]]>
        </Date_String>
        <Time_String><![CDATA[Thu at 6 pm]]>
        </Time_String>
        <Event_Name><![CDATA[Trio Voce]]>
        </Event_Name>
        <Event_Description><![CDATA[Free and engaging one-hour program of performance and conversation.]]>
        </Event_Description>
        <Ticket_String><![CDATA[Free]]>
        </Ticket_String>
    </event>
    <event>
        <Org_Name><![CDATA[Stanford Lively Arts]]>
        </Org_Name>
        <Venue_Name><![CDATA[Community School of Music and Arts]]>
        </Venue_Name>
        <Venue_address><![CDATA[230 San Antonio Circle]]>
        </Venue_address>
        <Event_Phone><![CDATA[650/725-ARTS]]>
        </Event_Phone>
        <Org_Web><![CDATA[HTTP://livelyarts.stanford.edu]]>
        </Org_Web>
        <Date_String><![CDATA[Apr 12]]>
        </Date_String>
        <Time_String><![CDATA[Tue at 6 pm]]>
        </Time_String>
        <Event_Name><![CDATA[Loren Schoenberg & Gunn High School Jazz Band]]>
        </Event_Name>
        <Event_Description><![CDATA[Free “Informance” at the Community School for Music and Arts featuring the music of jazz legend Charles Mingus in an engaging one-hour program of performance and conversation in Tateuchi Hall at the CSMA in Mountain View.]]>
        </Event_Description>
        <Ticket_String><![CDATA[Free]]>
        </Ticket_String>
    </event>

You will notice that of the three event nodes, two are from one Org_Name. How can I apply an xslt transform to output two event nodes, one of which is comprised of the two stanford event details.

Appreciate any help I can get. I have no time to learn xslt from the ground up.

lrlarson
NYC
0
Comment
Question by:lrlarson
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 34886030
The way you put it sounds like "can someone write me some code"
That is not what EE is meant for. For that you usually hire a consultant.

The task is not too hard, but requires some understanding of Muenchian grouping
http://www.jenitennison.com/xslt/grouping/muenchian.xml

Below is the XSLT, I hope you are willing to learn enough XSLT for possible changes you require
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">
    <xsl:output indent="yes" cdata-section-elements="Org_Name Venue_Name Venue_address Event_Phone Org_Web Date_String Time_String Event_Name Event_Description Ticket_String"/>
    <xsl:strip-space elements="*"/>
    <xsl:key name="ev" match="event" use="Org_Name"/>
    <xsl:template match="/">
        <events>
            <xsl:for-each select="//event[generate-id() = generate-id(key('ev', Org_Name)[1])]">
               <organisation>
                   <xsl:copy-of select="Org_Name | Venue_Name | Venue_address | Event_Phone | Org_Web"/>
                   <xsl:for-each select="key('ev', Org_Name)">
                       <event>
                           <xsl:copy-of select="Date_String | Time_String | Event_Name | Event_Description | Ticket_String"/>
                       </event>
                   </xsl:for-each>
               </organisation>
            </xsl:for-each>
        </events>
    </xsl:template>

</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:lrlarson
ID: 34887829
Thank you. I didn't mean my request to sound the way it evidently did, I just needed a pointer since I did not haver time to start from scratch.

Thank you for taking the time -- this is very helpful.
lrlarson
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 34887868
welcome
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unattended XML settings 4 123
XML namaspace 2 53
Change to event 1 119
Online tools to transform xml to excel using xsl 1 48
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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