Solved

a simple xml-xslt transformation

Posted on 2011-02-13
3
393 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
selectSingleNode in Access 2013 11 58
VB.Net and XML XSD Files 1 58
parse convert xml feed to text (python) 2 81
How to use xmlReader and idatareader  ? 4 56
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.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now