Reputation: 41
I have an atom feeds with lots of information and I would like to transform the needed information into an XML. The java code is already done, but I can not create the stylesheet for this tranformation.
<feed version="1.0" xmlns="http://www.w3.org/2005/Atom" xmlns:wwe="http://release.wwe.com/atom/1.0">
<id>http://release.wwe.com/wweatomfeed.atom</id>
<title><![CDATA[WWE Syndication Feed]]></title>
<subtitle>WWE Feed to syndicate WWE assets to domestic as well as international partners. This feed has custom modules for accommodating custom data transfer to clients.</subtitle>
<author><![CDATA[[email protected]]]></author>
<icon>http://release.wwe.com/media/storage_images/wwe-icon.jpg</icon>
<logo>http://release.wwe.com/media/storage_images/wwe-logo.jpg</logo>
<rights>2011 World Wrestling Entertainment!</rights>
<entry>
<id>26168987_26169027</id>
<title><![CDATA[WrestleMania 31]]></title>
<updated>2015-03-29T19:00:00-0400</updated>
<category term="WrestleMania"/>
<wwe:asset_type>Article</wwe:asset_type>
<author><![CDATA[john clapp]]></author>
<published>2015-03-29T19:00:00-0400</published>
<content><![CDATA[
Complete WrestleMania 31 coverage, news, videos, photos and more.
]]></content>
<wwe:shortSummary/>
<wwe:body><![CDATA[
]]></wwe:body>
<wwe:breadCrumb>Homepage#Shows#Wrestlemania#31</wwe:breadCrumb>
</entry>
<entry>
<id>26663863_26663903</id>
<title><![CDATA[WWE TLC 2014]]></title>
<updated>2014-12-14T20:00:00-0500</updated>
<category term="WWE TLC: Tables, Ladders and Chairs ... and Stairs"/>
<wwe:asset_type>Article</wwe:asset_type>
<author><![CDATA[john clapp]]></author>
<published>2014-12-14T20:00:00-0500</published>
<content><![CDATA[
WWE TLC: Tables, Ladders, and Chairs … and Stairs 2014 takes over Cleveland's Quicken Loans Arena on Sunday, Dec. 14, at 8 p.m. ET/5 p.m. PT.
]]></content>
<wwe:shortSummary/>
<wwe:body><![CDATA[
]]></wwe:body>
<wwe:breadCrumb>Homepage#Shows#Wwetlc#2014</wwe:breadCrumb>
</entry>
<entry>
<id>26898092_26898132</id>
<title><![CDATA[The Most Shocking Tables, Ladders & Chairs Moments]]></title>
<updated>2014-12-09T16:33:00-0500</updated>
<category term="Non-Branded"/>
<wwe:asset_type>Video</wwe:asset_type>
<link rel="enclosure" type="image/jpeg" href="http://us.wwe.com/f/video/thumb/2014/12/cdown_tlc_moments_updatedlogo.jpg"/>
<link rel="enclosure" type="video/x-flv" href="http://release.wwe.com/media/storage_video/26898092.flv"/>
<link rel="enclosure" type="video/mp4" href="http://release.wwe.com/media/storage_video/26898092.f4v"/>
<link rel="enclosure" type="video/x-ms-wmv" href="http://release.wwe.com/media/storage_video/26898092.wmv"/>
<link rel="enclosure" type="video/h264" href="http://release.wwe.com/media/storage_video/26898092.mp4"/>
<content><![CDATA[The Most Shocking Tables, Ladders & Chairs Moments]]></content>
<wwe:eventDate>2014-12-09T16:33:00-05:00</wwe:eventDate>
<wwe:releaseDate>2014-12-09T16:33:00-05:00</wwe:releaseDate>
<wwe:aspectRatio>
</wwe:aspectRatio>
<wwe:hours>0</wwe:hours>
<wwe:minutes>3</wwe:minutes>
<wwe:seconds>2</wwe:seconds>
<wwe:breadCrumb>Homepage#Videos#The-most-shocking-tables-ladders-chairs-moments-26898092</wwe:breadCrumb>
</entry>
</feed>
stylesheet used:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wwe="http://release.wwe.com/atom/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="/atom:feed/atom:entry[wwe:asset_type='Video']"/>
</xsl:template>
<!-- this template will delete the target nodes -->
<xsl:template match="/atom:feed/atom:entry[wwe:asset_type='Video']/atom:id|/atom:feed/atom:entry[wwe:asset_type='Video']/atom:updated|/atom:feed/atom:entry[wwe:asset_type='Video']/atom:category"/>
</xsl:stylesheet>
result:
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:wwe="http://release.wwe.com/atom/1.0">
<title>The Most Shocking Tables, Ladders & Chairs Moments</title>
<category term="Non-Branded"/>
<wwe:asset_type>Video</wwe:asset_type>
<link rel="enclosure" type="image/jpeg" href="http://us.wwe.com/f/video/thumb/2014/12/cdown_tlc_moments_updatedlogo.jpg"/>
<link rel="enclosure" type="video/x-flv" href="http://release.wwe.com/media/storage_video/26898092.flv"/>
<link rel="enclosure" type="video/mp4" href="http://release.wwe.com/media/storage_video/26898092.f4v"/>
<link rel="enclosure" type="video/x-ms-wmv" href="http://release.wwe.com/media/storage_video/26898092.wmv"/>
<link rel="enclosure" type="video/h264" href="http://release.wwe.com/media/storage_video/26898092.mp4"/>
<content>The Most Shocking Tables, Ladders & Chairs Moments</content>
<wwe:eventDate>2014-12-09T16:33:00-05:00</wwe:eventDate>
<wwe:releaseDate>2014-12-09T16:33:00-05:00</wwe:releaseDate>
<wwe:aspectRatio/>
<wwe:hours>0</wwe:hours>
<wwe:minutes>3</wwe:minutes>
<wwe:seconds>2</wwe:seconds>
<wwe:breadCrumb>Homepage#Videos#The-most-shocking-tables-ladders-chairs-moments-26898092</wwe:breadCrumb>
</entry>
what I actually need:
<rss xmlns="http://www.w3.org/2005/Atom" xmlns:wwe="http://release.wwe.com/atom/1.0">
<channel>
<title><![CDATA[WWE Syndication Feed]]></title>
<link>http://release.wwe.com/wweatomfeed.atom</link>
<description>WWE Feed to syndicate WWE assets to domestic as well as international partners. This feed has custom modules for accommodating custom data transfer to clients</description>
<rights>2011 World Wrestling Entertainment!</rights>
<item>
<title>The Most Shocking Tables, Ladders & Chairs Moments</title>
<category term="Non-Branded"/>
<media:group>
<media:content type="video/mp4" url="http://release.wwe.com/media/storage_video/26898092.f4v"/>
<media:content type="image/jpeg" url="http://us.wwe.com/f/video/thumb/2014/12/cdown_tlc_moments_updatedlogo.jpg"/>
</media:group>
</item>
<item>
.
.
.
.
.
.
</item>
</channel>
</rss>
Upvotes: 0
Views: 1100
Reputation: 7173
I think this simple stylesheet would answer your problem:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wwe="http://release.wwe.com/atom/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:media="wwww.yourmedia.com"
exclude-result-prefixes="atom"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<rss xmlns="http://www.w3.org/2005/Atom">
<xsl:element name="title" namespace="http://www.w3.org/2005/Atom"/>
<xsl:element name="link" namespace="http://www.w3.org/2005/Atom"/>
<xsl:element name="description" namespace="http://www.w3.org/2005/Atom"/>
<xsl:for-each select="/atom:feed/atom:entry[*[local-name()='asset_type'][.='Video']]">
<xsl:element name="item" namespace="http://www.w3.org/2005/Atom">
<xsl:apply-templates select="atom:title"/>
<xsl:apply-templates select="atom:category"/>
<xsl:if test="atom:link">
<media:group>
<xsl:apply-templates select="atom:link[@type='video/mp4']"/>
<xsl:apply-templates select="atom:link[@type='image/jpeg']"/>
</media:group>
</xsl:if>
</xsl:element>
</xsl:for-each>
</rss>
</xsl:template>
<xsl:template match="atom:link">
<media:content>
<xsl:apply-templates select="@*[not(name()='rel')]"/>
</media:content>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1
Reputation: 640
try out this
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="msxsl wwe test atom"
xmlns:test="http://test.com/atom/1.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wwe="http://release.wwe.com/atom/1.0"
version="1.0">
<xsl:template match="/">
<good>
<xsl:for-each select="atom:feed/atom:entry">
<assettype>
<xsl:if test="test:asset_type='VIDEO'">
<xsl:copy-of select="current()"/>
</xsl:if>
<xsl:if test="wwe:asset_type='VIDEO'">
<xsl:copy-of select="current()"/>
</xsl:if>
<xsl:if test="test:asset_type='Video'">
<xsl:copy-of select="current()"/>
</xsl:if>
<xsl:if test="wwe:asset_type='Video'">
<xsl:copy-of select="current()"/>
</xsl:if>
</assettype>
</xsl:for-each>
</good>
</xsl:template>
</xsl:stylesheet>
you xml is invalid cause "wwe" prefix hasn't been defined. That is why i have assumed that is exists in you xml by using the following namespace "Check". This will vary for your xml but you will have to change the xslt namespace portion accordingly
Upvotes: 0