Solved

a simple xml-xslt transformation

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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, …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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