我正在尝试规范化一段 xml。我在与ProductID
. 我正在尝试为它创建一个容器,但<products><productid>xyz</productid></products>
我<xsl:for-each select="ProductID">
似乎不起作用。谁能指出我正确的方向?
<Batch>
<Promotion>
<PromotionID>000873</PromotionID>
<Description country="GB" language="en" variant="">*P* Free Clotted Cream Scone</Description>
<MultibuyGroup>
<RewardType>1</RewardType>
<RewardValue>0.0</RewardValue>
<RewardValue currency="GBP">1.0</RewardValue>
<ProductID>1300003536</ProductID>
<ProductID>1300000746</ProductID>
<ProductID>1300002393</ProductID>
<ProductID>1300002648</ProductID>
<ProductID>1300002899</ProductID>
<ProductID>1300003535</ProductID>
<ProductID>1300003222</ProductID>
</MultibuyGroup>
<MultibuyGroup>
<RewardType>0</RewardType><RewardValue>0.0</RewardValue>
<RewardValue currency="GBP">0.0</RewardValue>
<ProductID>1570000102</ProductID>
</MultibuyGroup>
<Timetable>
<SartDate>2008-02-02T00:00:00+00:00</StartDate>
<FinishDate>2008-02-03T23:59:59+00:00</FinishDate>
</Timetable>
</Promotion>
</Batch>
我试图让它看起来像。
<Batch>
<Promotion>
<PromotionID>000873</PromotionID>
<badge_id>tbc</badge_id>
<loyaltyaccountholdersonly>TBC</loyaltyaccountholdersonly>
<locations>TBC</locations>
<Description country="GB" language="en" variant="">*P* Free Clotted Cream Scone</Description>
<MultibuyGroup>
<RewardType>1</RewardType>
<RewardValue>0.0</RewardValue>
<RewardValue currency="GBP">1.0</RewardValue>
<products>
<ProductID>1300003536</ProductID>
<ProductID>1300000746</ProductID>
<ProductID>1300002393</ProductID>
<ProductID>1300002648</ProductID>
<ProductID>1300002899</ProductID>
<ProductID>1300003535</ProductID>
<ProductID>1300003222</ProductID>
</products>
</MultibuyGroup>
<MultibuyGroup>
<RewardType>0</RewardType><RewardValue>0.0</RewardValue>
<RewardValue currency="GBP">0.0</RewardValue>
<ProductID>1570000102</ProductID>
</MultibuyGroup>
<Timetable>
<SartDate>2008-02-02T00:00:00+00:00</StartDate>
<FinishDate>2008-02-03T23:59:59+00:00</FinishDate>
</Timetable>
</Promotion>
</Batch>
使用以下 XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<promotions>
<xsl:for-each select="Batch/Promotion">
<promotion>
<promotion_id><xsl:value-of select="PromotionID"/></promotion_id>
<badge_id>TBC</badge_id>
<loyaltyaccountholdersonly>TBC</loyaltyaccountholdersonly>
<description><xsl:value-of select="Description[@country = 'GB']"/></description>
<locations>TBC</locations>
<xsl:for-each select="MultibuyGroup">
<multibuygroup>
<products>
<xsl:for-each select="ProductID">
<product_id><xsl:value-of select="ProductID"/></product_id>
</xsl:for-each>
</products>
<rewardtype><xsl:value-of select="RewardType"/></rewardtype>
<rewardvalue><xsl:value-of select="RewardValue"/></rewardvalue>
<rewardthreshold>TBC</rewardthreshold>
<groupdescription><xsl:value-of select="GroupDescription"/></groupdescription>
</multibuygroup>
</xsl:for-each>
<timetable>
<startdate><xsl:value-of select="Timetable/StartDate"/></startdate>
<expirydate><xsl:value-of select="Timetable/FinishDate"/></expirydate>
</timetable>
</promotion>
</xsl:for-each>
</promotions>
</xsl:template>
</xsl:stylesheet>