我是第一次发帖,所以如果我做错了,请接受我的道歉。 。 基本上我正在尝试的是使用XSLT从XML创建XML。我尝试在线参考示例但我找不到类似的东西。 我正在尝试的可以分为3个主要步骤:
为3种不同的方法设置模板。创建,更新和 清除。创建和更新需要一些逻辑来转换XML 而Purge方法将解析XML。
将部分XML从PromoMessage标记解析为结束标记以进行分发。
在XML中实际输出的字段包含我引用的标记的值。
以下是源XML的两个示例:
Source 1是最复杂的源,它需要逻辑来选择插页式类别并提升程序类型,创建的方法应该参考使用这个逻辑。更新方法的工作方式相同:
<?xml version="1.0" ?>
<PromoMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Header origin="IBMSV6" method="create" timestamp="2013-08-06T06:32:17Z" />
<Body>
<CreatePromo providerId="NJR" promoID="245686_NJ01858S ">
<Distribution>
<RightsWindow start="2013-07-31T14:00:00Z" end="2013-08-31T13:59:59Z" />
<Destinations>
<Destination platform="WCMS" site="EPG" visible="true">
<DisplayWindow start="2013-07-31T14:00:00Z" end="2013-08-31T13:59:59Z" />
</Destination>
</Destinations>
</Distribution>
<Interstitial category= "episodic" multi_prog="false" name="Promo Alpha" parentalRating ="PG" >
<PromotedProgramme type ="MovieOrEvent" seq_number ="1" > //promoted prog non-series
<TitleId>000000218564</TitleId>
<ExternalProgId>785432</ExternalProgId>
<TitleBroadcastRef>078654</TitleBroadcastRef>
<TitleName>Men In Black</TitleName>
</PromotedProgramme>
<PromotedProgramme type ="MoviefssOrEvent" seq_number ="2"> <!--promoted slot non-series-->
<SlotId>675342</SlotId>
<SlotName>Late Movie</SlotName>
<TitleId>000000218576</TitleId>
<ExternalProgId>785632</ExternalProgId>
<TitleBroadcastRef>078123</TitleBroadcastRef>
<TitleName>Die Hard</TitleName>
<EPGTitleName>Die Hard</EPGTitleName>
</PromotedProgramme>
<PromotedProgramme type ="Series" seq_number ="3"> <!--promoted prog series-->
<TitleId>000000218321</TitleId>
<ExternalProgId>785122</ExternalProgId>
<TitleBroadcastRef>075432</TitleBroadcastRef>
<TitleName> Friends S5 Ep5</TitleName>
<EpisodeNo>10</EpisodeNo>
<SeasonId>10645346</SeasonId>
<SeasonName>Friends</SeasonName>
<SeasonNo>5</SeasonNo>
<SeasonYear>5</SeasonYear>
<ShowId>10987532</ShowId>
<ShowName>Friends</ShowName>
<EPGTitleName>Friends</EPGTitleName>
</PromotedProgramme>
<PromotedProgramme type ="Slot" seq_number ="4"> <!--promoted slot - no prog or title assigned to slot-->
<SlotId>675347</SlotId>
<SlotName>Late Movie</SlotName>
</PromotedProgramme>
<PromotedProgramme type ="ExtChannel" seq_number ="5"> <!--promoted prog from ext.channel-->
<PromotedBroadcastRef>675347</PromotedBroadcastRef >
</PromotedProgramme>
</Interstitial>
<Media>
<Source>playout</Source>
<Identifier>NJ01858S </Identifier>
<AspectRatio>16X9 </AspectRatio>
</Media>
</CreatePromo>
</Body>
</PromoMessage>
源2是一个清除请求,需要根据以下方法进行解析:
- <PromoMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Header origin="IBMSV6" method="purge" timestamp="2013-08-06T06:34:07Z" />
- <Body>
- <PurgePromo providerId="NJR" promoID="245685_NJ01857S">
- <Distribution>
- <Destinations>
<Destination platform="WCMS" site="EPG" />
</Destinations>
</Distribution>
</PurgePromo>
</Body>
</PromoMessage>
这是我目前的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<!--xsl:template match="PromoMessage/Header[@method]='purge'"/-->
<PromoMessage>
<!--xsl:variable name="origin"/>
<xsl:variable name="method"/>
<xsl:variable name="timestamp"/>
<xsl:variable name="providerId"/>
<xsl:variable name="promoID"/>
<xsl:variable name="RWstart"/>
<xsl:variable name="RWend"/>
<xsl:variable name="platform"/>
<xsl:variable name="site"/>
<xsl:variable name="visible"/>
<xsl:variable name="DWstart"/>
<xsl:variable name="DWend"/-->
<Header>
<xsl:apply-templates select="PromoMessage/Header"/>
<xsl:attribute name="origin">
<xsl:value-of select="PromoMessage/Header[@origin]"/>
</xsl:attribute>
<!--xsl:variable name="method">
<xsl:if test="PromoMessage/Header[@method]='create' or 'update'"></xsl:if>
<xsl:if test="PromoMessage/Header[@method]='purge'"></xsl:if>
</xsl:variable-->
<xsl:attribute name="method">
<xsl:value-of select="/"/>
</xsl:attribute>
<xsl:attribute name="timestamp">
<xsl:value-of select="/"/>
</xsl:attribute>
</Header>
<Body>
<xsl:apply-templates select="PromoMessage/Header/Body"/>
<CreatePromo>
<xsl:attribute name="providerId">
<xsl:value-of select="@providerId"/>
</xsl:attribute>
<xsl:attribute name="promoID">
<xsl:value-of select="@promoID"/>
</xsl:attribute>
<Distribution>
<RightsWindow>
<xsl:attribute name="start">
<xsl:value-of select="@start"/>
</xsl:attribute>
<xsl:attribute name="end">
<xsl:value-of select="@end"/>
</xsl:attribute>
</RightsWindow>
<Destinations>
<Destination>
<xsl:attribute name="platform">
<xsl:value-of select="@platform"/>
</xsl:attribute>
<xsl:attribute name="site">
<xsl:value-of select="@site"/>
</xsl:attribute>
<xsl:attribute name="visible" >
<xsl:value-of select="@visible"/>
</xsl:attribute>
<DisplayWindow>
<xsl:attribute name="start">
<xsl:value-of select="@start"/>
</xsl:attribute>
<xsl:attribute name="end">
<xsl:value-of select="@end"/>
</xsl:attribute>
</DisplayWindow>
</Destination>
</Destinations>
</Distribution>
<EventLink>
<xsl:choose>
<!--Interstitial Category episodic & Promoted Programme Type MovieOrEvent-->
<xsl:when test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme/@type='MovieOrEvent'">
<xsl:attribute name="type">
<xsl:value-of select="@category"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='MovieOrEvent']/EPGTitleName != '0'">
<xsl:value-of select="EPGTitleName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='MovieOrEvent']/TitleName != '0'">
<xsl:value-of select="TitleName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='MovieOrEvent']/SlotName != '0'">
<xsl:value-of select="SlotName"/>
</xsl:if>
</xsl:attribute>
<xsl:attribute name="parentalRating">
<xsl:value-of select="@parentalRating"/>
</xsl:attribute>
<Programme>
<ProgrammeId>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='MovieOrEvent']/ExternalProgId != '0'">
<xsl:value-of select ="ExternalProgId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='MovieOrEvent']/TitleId != '0'">
<xsl:value-of select ="TitleId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='MovieOrEvent']/SlotId != '0'">
<xsl:text>S</xsl:text><xsl:value-of select ="SlotId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='MovieOrEvent']/PromotedBroadcastRef != '0'">
<xsl:value-of select ="PromotedBroadcastRef"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='MovieOrEvent']/TitleBroadcastRef != '0'">
<xsl:value-of select ="TitleBroadcastRef"/></xsl:if>
</ProgrammeId>
</Programme>
</xsl:when>
<!--Interstitial Category episodic & Promoted Programme Type Series-->
<xsl:when test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme/@type='Series'">
<xsl:attribute name="type">
<xsl:value-of select="@category"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/EPGTitleName != '0'">
<xsl:value-of select="EPGTitleName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/SeasonName != '0'">
<xsl:value-of select="SeasonName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/TitleName != '0'">
<xsl:value-of select="TitleName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/SlotName != '0'">
<xsl:value-of select="SlotName"/>
</xsl:if>
</xsl:attribute>
<xsl:attribute name="parentalRating">
<xsl:value-of select="@parentalRating"/>
</xsl:attribute>
<Programme>
<ProgrammeId>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/ExternalProgId != '0'">
<xsl:value-of select ="ExternalProgId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/TitleId != '0'">
<xsl:value-of select ="TitleId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/SlotId != '0'">S
<xsl:value-of select ="SlotId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/PromotedBroadcastRef != '0'">
<xsl:value-of select ="PromotedBroadcastRef"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Series']/TitleBroadcastRef != '0'">
<xsl:value-of select ="TitleBroadcastRef"/></xsl:if>
</ProgrammeId>
</Programme>
</xsl:when>
<!--Interstitial Category episodic & Promoted Programme Type Slot-->
<xsl:when test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme/@type='Slot'">
<xsl:attribute name="type">
<xsl:value-of select="@category"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/EPGTitleName != '0'">
<xsl:value-of select="EPGTitleName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/SeasonName != '0'">
<xsl:value-of select="SeasonName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/TitleName != '0'">
<xsl:value-of select="TitleName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/SlotName != '0'">
<xsl:value-of select="SlotName"/>
</xsl:if>
</xsl:attribute>
<xsl:attribute name="parentalRating">
<xsl:value-of select="@parentalRating"/>
</xsl:attribute>
<Programme>
<ProgrammeId>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/ExternalProgId != '0'">
<xsl:value-of select ="ExternalProgId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/TitleId != '0'">
<xsl:value-of select ="TitleId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/SlotId != '0'">S
<xsl:value-of select ="SlotId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/PromotedBroadcastRef != '0'">
<xsl:value-of select ="PromotedBroadcastRef"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='Slot']/TitleBroadcastRef != '0'">
<xsl:value-of select ="TitleBroadcastRef"/></xsl:if>
</ProgrammeId>
</Programme>
</xsl:when>
<!--Interstitial Category episodic & Promoted Programme Type ExtChannel-->
<xsl:when test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme/@type='ExtChannel'">
<xsl:attribute name="type">
<xsl:value-of select="@category"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/EPGTitleName != '0'">
<xsl:value-of select="EPGTitleName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/SeasonName != '0'">
<xsl:value-of select="SeasonName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/TitleName != '0'">
<xsl:value-of select="TitleName"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/SlotName != '0'">
<xsl:value-of select="SlotName"/>
</xsl:if>
</xsl:attribute>
<xsl:attribute name="parentalRating">
<xsl:value-of select="@parentalRating"/>
</xsl:attribute>
<Programme>
<ProgrammeId>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/ExternalProgId != '0'">
<xsl:value-of select ="ExternalProgId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/TitleId != '0'">
<xsl:value-of select ="TitleId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/SlotId != '0'">S
<xsl:value-of select ="SlotId"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/PromotedBroadcastRef != '0'">
<xsl:value-of select ="PromotedBroadcastRef"/></xsl:if>
<xsl:if test="PromoMessage/Body/CreatePromo/Interstitial[@category='episodic']/PromotedProgramme[@type='ExtChannel']/TitleBroadcastRef != '0'">
<xsl:value-of select ="TitleBroadcastRef"/></xsl:if>
</ProgrammeId>
</Programme>
</xsl:when>
</xsl:choose>
<Media>
<Source>
<Videos>
<Video>
<xsl:attribute name="source">
<xsl:value-of select="@Source"/>
</xsl:attribute>
<xsl:attribute name="Identifier">
<xsl:value-of select="@Identifier"/>
</xsl:attribute>
<xsl:attribute name="aspect_ratio">
<xsl:value-of select="@AspectRatio"/>
</xsl:attribute>
</Video>
</Videos>
</Source>
</Media>
</CreatePromo>
</Body>
</PromoMessage>
</xsl:template>
</xsl:stylesheet>
以下是使用Source 1 XML的XSLT的输出:
<?xml version="1.0" encoding="UTF-8"?>
<PromoMessage xmlns:xs="http://www.w3.org/2001/XMLSchema">
<Header origin="" method=" //promoted prog non-series
 000000218564785432078654Men In Black675342Late Movie000000218576785632078123Die HardDie Hard000000218321785122075432 Friends S5 Ep51010645346Friends5510987532FriendsFriends675347Late Movie675347playoutNJ01858S 16X9 " timestamp=" //promoted prog non-series
 000000218564785432078654Men In Black675342Late Movie000000218576785632078123Die HardDie Hard000000218321785122075432 Friends S5 Ep51010645346Friends5510987532FriendsFriends675347Late Movie675347playoutNJ01858S 16X9 "/>
<Body>
<CreatePromo providerId="" promoID="">
<Distribution>
<RightsWindow start="" end=""/>
<Destinations>
<Destination platform="" site="" visible="">
<DisplayWindow start="" end=""/>
</Destination>
</Destinations>
</Distribution>
<EventLink type="" title="" parentalRating="">
<Programme>
<ProgrammeId></ProgrammeId>
</Programme>
</EventLink>
<Media>
<Source>
<Videos>
<Video source="" Identifier="" aspect_ratio=""/>
</Videos>
</Source>
</Media>
</CreatePromo>
</Body>
</PromoMessage>
以下是输出的外观:
<?xml version="1.0" ?>
- <PromoMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Header origin="IBMSV6" method="create" timestamp="2013-08-06T06:32:17Z" />
<Body>
<CreatePromo providerId="NJR" promoID="245686_NJ01858S">
<Distribution>
<RightsWindow start="2013-07-31T14:00:00Z" end="2013-08-31T13:59:59Z" />
<Destinations>
<Destination platform="WCMS" site="EPG" visible="true">
<DisplayWindow start="2013-07-31T14:00:00Z" end="2013-08-31T13:59:59Z" />
</Destination>
</Destinations>
</Distribution>
<EventLink type="episodic" title="Men In Black" parentalRating="PG">
<!-- title from Listing Text Set Title
-->
<Programme>
<ProgrammeId>785432</ProgrammeId>
<!-- From ExtProgId (if it exists) or title ID
-->
</Programme>
</EventLink>
<Media>
<Source>
<Videos>
<Video source="playout" Identifier="NJ01858S" aspect_ratio="16X9" />
</Videos>
</Source>
</Media>
</CreatePromo>
</Body>
</PromoMessage>
如果有人能指出我正确的方向,我当然会很感激,谢谢。
答案 0 :(得分:0)
我可以回答你关于第一步的问题,因为这是我认为的唯一部分(?)我明白了:
创建和更新需要一些逻辑来转换XML Purge方法将解析XML。
您的XSLT需要具有以下基本结构:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/PromoMessage[Header/@method='create' or Header/@method='update']">
<!-- logic to process "create/update" message types -->
</xsl:template>
<xsl:template match="/PromoMessage[Header/@method='purge']">
<!-- logic to process "purge" message type -->
</xsl:template>
</xsl:stylesheet>
我不太清楚你的意思:
Purge方法将解析XML。
如果通过&#34;解析&#34;你的意思是&#34;传递&#34; - 即按,然后逻辑处理&#34;清除&#34;消息类型可以非常简单:
<xsl:template match="/PromoMessage[Header/@method='purge']">
<xsl:copy-of select="."/>
</xsl:template>
我建议您针对任何特定问题发布单独的问题,并处理&#34;创建/更新&#34;消息类型。