Solved

a simple xml-xslt transformation

Posted on 2011-02-13
3
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

628 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