2017-05-08 40 views
0

忙於在XSL模板中卡住,並遇到輕微問題。for-each的XLS模板問題

使用下面的模板代碼:

productlisting.xsl

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
    <html> 
    <body> 
    <h2>TFG Product File</h2> 
    <table border="1"> 
    <tr bgcolor="#9acd32"> 
     <th>ProductID</th> 
     <th>ProductName</th> 
    </tr> 
    <xsl:for-each select="ProductFile/Products"> 
     <tr> 
     <td><xsl:value-of select="ProductFile/Products/Id"/></td> 
     <td><xsl:value-of select="ProductFile/Products/LocalizedProductList/DisplayName"/></td> 
     </tr> 
    </xsl:for-each> 
    </table> 
    </body> 
    </html> 
</xsl:template> 

</xsl:stylesheet> 

這裏是兩個產品的XML文件:

productcatalog.xml

<?xml version="1.0" encoding="utf-8"?> 
<?xml-stylesheet type="text/xsl" href="productlisting.xsl"?> 
<ProductFile> 
    <SiteId>1011</SiteId> 
    <Products> 
     <TFGMerchandisingId>251100AAAC0</TFGMerchandisingId> 
     <Id>251100AAAC0</Id> 
     <TFGMerchandisingDescription>MELTON COAT TOBACCO</TFGMerchandisingDescription> 
     <TFGMerchandisingDescriptionLong>MELTON COAT TOBACCO</TFGMerchandisingDescriptionLong> 
     <Type>ColourSize</Type> 
     <SubType></SubType> 
     <VideoUrl></VideoUrl> 
     <TFGMerchandisingStatus>1</TFGMerchandisingStatus> 
     <TFGMerchandisingStatusDescription>Open</TFGMerchandisingStatusDescription> 
     <TFGMerchandisingCreateDate>2017-04-23T16:57:42.983</TFGMerchandisingCreateDate> 
     <TFGMerchandisingPisDate>2017-03-31T00:00:00</TFGMerchandisingPisDate> 
     <TFGMerchandisingCommodity>1100</TFGMerchandisingCommodity> 
     <TFGMerchandisingCommodityDescription>FB SMART JACKETS</TFGMerchandisingCommodityDescription> 
     <TFGMerchandisingBuyersClass>110001</TFGMerchandisingBuyersClass> 
     <TFGMerchandisingBuyersClassDescription>OVERCOATS</TFGMerchandisingBuyersClassDescription> 
     <TFGMerchandisingMaterial>WOOL BLENDS</TFGMerchandisingMaterial> 
     <TFGMerchandisingWeight>0.00</TFGMerchandisingWeight> 
     <TFGMerchandisingCubeVolume>0</TFGMerchandisingCubeVolume> 
     <TFGMerchandisingBrandName>FABIANI</TFGMerchandisingBrandName> 
     <BrandCode>25</BrandCode> 
     <CrossSellProductId1></CrossSellProductId1> 
     <CrossSellProductId2></CrossSellProductId2> 
     <CrossSellProductId3></CrossSellProductId3> 
     <DisableCompareOption>false</DisableCompareOption> 
     <DisableNextDayDelivery>false</DisableNextDayDelivery> 
     <RequiresRica>false</RequiresRica> 
     <RequiresId>false</RequiresId> 
     <RequiresTVLicense>false</RequiresTVLicense> 
     <RequiresDeposit>false</RequiresDeposit> 
     <InstallmentAvailable>false</InstallmentAvailable> 
     <StaffDiscountAllowed>true</StaffDiscountAllowed> 
     <StaffDiscountOverride>false</StaffDiscountOverride> 
     <MaxDiscountAllowed>40.00</MaxDiscountAllowed> 
     <SizeChartIconUrl></SizeChartIconUrl> 
     <PdfIconUrl></PdfIconUrl> 
     <IsNavigable>true</IsNavigable> 
     <TFGMerchandisingTypeCode></TFGMerchandisingTypeCode> 
     <TFGMerchandisingTypeDescription>FABIANI</TFGMerchandisingTypeDescription> 
     <Groups> 
      <GroupSequence>1</GroupSequence> 
      <GroupId>8c5f3f15-7a57-4186-bd29-3f7f6a3b106f</GroupId> 
      <LocalizedGroupList> 
       <Locale>en_ZA</Locale> 
       <Group>Default</Group> 
      </LocalizedGroupList> 
      <Attributes> 
       <AttributeId>9dd85915-f977-4596-9d35-10d3e23aef1c</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Style Detail</Name> 
        <Value>Peak lapels Fully lined Single vent Flap pockets</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>47fa52e8-44d6-45f3-8249-906434f6e399</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Size &amp; Fit</Name> 
        <Value>Regular Fit To ensure every Fabiani garment is the perfect fit for you, please refer to our size guide and check our measurements.</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>823e6a08-a906-4b2e-9fc1-35c332d263d0</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Fabric</Name> 
        <Value>Wool blends</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>1abbda7a-3f92-4eee-b414-7516c4eb0fe3</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Care</Name> 
        <Value>Do Not Wash Do Not Bleach Cool Iron Dry-clean Only Do Not Tumble Dry</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>479d96a4-f8a7-4048-876a-da9134d03ed1</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Models size</Name> 
        <Value>Model wearing a large Model measures: chest 39"/ 99cm, waist 32, height 74'02"/ 188cm</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
     </Groups> 
     <LocalizedProductList> 
      <Locale>en_ZA</Locale> 
      <DisplayName>MELTON COAT</DisplayName> 
      <Description>A modern wardrobe essential, our stylish overcoat is expertly crafted into a slim yet unrestrictive silhouette from luxuriously soft Melton, ensuring warmth and comfort on colder days. The single vent allows for freedom of movement while the lining allows it to easily layer over jackets and knitwear.</Description> 
      <Widget1Url></Widget1Url> 
      <Widget2Url></Widget2Url> 
      <Widget3Url></Widget3Url> 
      <Tabs> 
       <Name>Product Information</Name> 
       <Description></Description> 
      </Tabs> 
      <SizeChartUrl></SizeChartUrl> 
      <SizeChartToolTip></SizeChartToolTip> 
      <PdfUrl></PdfUrl> 
      <PdfToolTip></PdfToolTip> 
      <SeoTitle>MELTON COAT</SeoTitle> 
     </LocalizedProductList> 
     <Colours> 
      <TFGMerchandisingStyleId>21303875</TFGMerchandisingStyleId> 
      <DefaultStyleId>21303875</DefaultStyleId> 
      <TFGMerchandisingColourId>21303875</TFGMerchandisingColourId> 
      <TFGMerchandisingColourDescription>LIGHT GREY</TFGMerchandisingColourDescription> 
      <TFGMerchandisingGeneric>GREY</TFGMerchandisingGeneric> 
      <ImageMainPrimary>/25/Detail/21303875.jpg</ImageMainPrimary> 
      <ImageMainAlts> 
       <URL>/25/DetailAlternative/21303875_01.jpg</URL> 
      </ImageMainAlts> 
      <ImageMainAlts> 
       <URL>/25/DetailAlternative/21303875_02.jpg</URL> 
      </ImageMainAlts> 
      <ImageThumbPrimary>/25/Thumbnail/21303875.jpg</ImageThumbPrimary> 
      <ImageThumbAlts> 
       <URL>/25/ThumbnailAlternative/21303875_01.jpg</URL> 
      </ImageThumbAlts> 
      <ImageThumbAlts> 
       <URL>/25/ThumbnailAlternative/21303875_02.jpg</URL> 
      </ImageThumbAlts> 
      <ImageSearchPrimary>/25/Listing/21303875.jpg</ImageSearchPrimary> 
      <Swatch>/25/ColourSwatch/21303875_SW.jpg</Swatch> 
      <DisableEmailMe>false</DisableEmailMe> 
      <DisableAddToGiftList>false</DisableAddToGiftList> 
      <DisableAddToWishList>false</DisableAddToWishList> 
      <DisableAddToCart>false</DisableAddToCart> 
      <RemoveFromOnlineCatalogue>false</RemoveFromOnlineCatalogue> 
      <LocalizedColourList> 
       <Locale>en_ZA</Locale> 
       <SeoTitle></SeoTitle> 
      </LocalizedColourList> 
      <Sizes> 
       <Sku>21303883</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>8</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>44 CHEST L</Description> 
        <SkuDisplayName>44 CHEST L</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303885</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>10</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>46 CHEST L</Description> 
        <SkuDisplayName>46 CHEST L</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303884</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>9</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>46 CHEST</Description> 
        <SkuDisplayName>46 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303876</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>3</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>36 CHEST</Description> 
        <SkuDisplayName>36 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303889</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>14</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>54 CHEST</Description> 
        <SkuDisplayName>54 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303888</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>13</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>52 CHEST</Description> 
        <SkuDisplayName>52 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303882</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>7</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>44 CHEST</Description> 
        <SkuDisplayName>44 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303878</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>5</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>40 CHEST</Description> 
        <SkuDisplayName>40 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303886</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>11</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>48 CHEST</Description> 
        <SkuDisplayName>48 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303880</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>2</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>None</Description> 
        <SkuDisplayName>None</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303887</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>12</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>50 CHEST</Description> 
        <SkuDisplayName>50 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303881</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>6</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>42 CHEST L</Description> 
        <SkuDisplayName>42 CHEST L</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303879</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>1</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>None</Description> 
        <SkuDisplayName>None</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
      <Sizes> 
       <Sku>21303877</Sku> 
       <CompanyId>02</CompanyId> 
       <Sequence>4</Sequence> 
       <PlanUrl></PlanUrl> 
       <IsActive>true</IsActive> 
       <OnSale>false</OnSale> 
       <StoreStockDisplay>Always</StoreStockDisplay> 
       <LocalizedSizeList> 
        <Locale>en_ZA</Locale> 
        <Description>38 CHEST</Description> 
        <SkuDisplayName>38 CHEST</SkuDisplayName> 
       </LocalizedSizeList> 
      </Sizes> 
     </Colours> 
     <ServiceProviderUrl></ServiceProviderUrl> 
     <RewardCode>66</RewardCode> 
     <IsDiscountable>true</IsDiscountable> 
     <BrandImageURL>/25/BrandImage/fabiani.jpg</BrandImageURL> 
    </Products> 
    <Products> 
     <TFGMerchandisingId>194217AAAF6</TFGMerchandisingId> 
     <Id>194217AAAF6</Id> 
     <TFGMerchandisingDescription>TH CHASM DUFFEL L GREY</TFGMerchandisingDescription> 
     <TFGMerchandisingDescriptionLong>TH CHASM DUFFEL L GREY</TFGMerchandisingDescriptionLong> 
     <Type>ColourNoSize</Type> 
     <SubType></SubType> 
     <VideoUrl></VideoUrl> 
     <TFGMerchandisingStatus>2</TFGMerchandisingStatus> 
     <TFGMerchandisingStatusDescription>On Clearance</TFGMerchandisingStatusDescription> 
     <TFGMerchandisingCreateDate>2017-03-28T07:36:58.567</TFGMerchandisingCreateDate> 
     <TFGMerchandisingPisDate>2015-11-04T14:59:54.313</TFGMerchandisingPisDate> 
     <TFGMerchandisingCommodity>4217</TFGMerchandisingCommodity> 
     <TFGMerchandisingCommodityDescription>Duffel Bags</TFGMerchandisingCommodityDescription> 
     <TFGMerchandisingBuyersClass>421702</TFGMerchandisingBuyersClass> 
     <TFGMerchandisingBuyersClassDescription>Large</TFGMerchandisingBuyersClassDescription> 
     <TFGMerchandisingMaterial>TPE Laminate</TFGMerchandisingMaterial> 
     <TFGMerchandisingWeight>0.00</TFGMerchandisingWeight> 
     <TFGMerchandisingCubeVolume>0</TFGMerchandisingCubeVolume> 
     <TFGMerchandisingBrandName>Thule</TFGMerchandisingBrandName> 
     <BrandCode>19</BrandCode> 
     <CrossSellProductId1></CrossSellProductId1> 
     <CrossSellProductId2></CrossSellProductId2> 
     <CrossSellProductId3></CrossSellProductId3> 
     <DisableCompareOption>false</DisableCompareOption> 
     <DisableNextDayDelivery>false</DisableNextDayDelivery> 
     <RequiresRica>false</RequiresRica> 
     <RequiresId>false</RequiresId> 
     <RequiresTVLicense>false</RequiresTVLicense> 
     <RequiresDeposit>false</RequiresDeposit> 
     <InstallmentAvailable>false</InstallmentAvailable> 
     <StaffDiscountAllowed>true</StaffDiscountAllowed> 
     <StaffDiscountOverride>false</StaffDiscountOverride> 
     <MaxDiscountAllowed>40.00</MaxDiscountAllowed> 
     <SizeChartIconUrl></SizeChartIconUrl> 
     <PdfIconUrl></PdfIconUrl> 
     <IsNavigable>true</IsNavigable> 
     <TFGMerchandisingTypeCode></TFGMerchandisingTypeCode> 
     <TFGMerchandisingTypeDescription></TFGMerchandisingTypeDescription> 
     <Groups> 
      <GroupSequence>1</GroupSequence> 
      <GroupId>a9c1c190-5882-4e41-85a7-e0b14096f786</GroupId> 
      <LocalizedGroupList> 
       <Locale>en_ZA</Locale> 
       <Group>Default</Group> 
      </LocalizedGroupList> 
      <Attributes> 
       <AttributeId>e07ef650-9719-4022-b0c0-c2837f04c856</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>End Use</Name> 
        <Value>Traveller</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>20b2e363-3364-4d54-90ce-51b26edebc2b</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Fabrication</Name> 
        <Value>TPE Laminate</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>35da6c1c-bd22-4858-a1d4-33508456d13c</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Capacity</Name> 
        <Value>90 l</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>b970e2f9-b7ff-407b-9b3b-2a82eab95e99</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Weight</Name> 
        <Value>1.2 kg</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>468d3dc8-16e8-4327-85c7-e118d25c82cd</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Dimensions</Name> 
        <Value>External height 33 cm 
External length 74 cm 
External depth 42 cm</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
      <Attributes> 
       <AttributeId>996f1e59-97bc-4f99-8695-89c4e49c4f9c</AttributeId> 
       <LocalizedAttributeList> 
        <Locale>en_ZA</Locale> 
        <Name>Features</Name> 
        <Value>Oversized, wide mouth opening make it easy to pack and easy to get to your gear. 
Side access makes it easy to reach the main compartment from any angle 
Duffel straps stow cleanly along the side of the duffel. 
Straps quickly convert the bag from a backpack to a duffel. 
Durable, water proof tarpaulin fabric stands up on its own for easy packing but easily folds for storage. 
Internal mesh pockets keep your gear organized. 
External compression straps prevent bag contents from falling to the bottom of the bag when in backpack mode. 
Padded bottom cushions your gear from the ground. 
Locking zippers deter thieves (lock sold separately). 
Exterior stash pocket stores small items.</Value> 
        <TooltipText></TooltipText> 
       </LocalizedAttributeList> 
      </Attributes> 
     </Groups> 
     <LocalizedProductList> 
      <Locale>en_ZA</Locale> 
      <DisplayName>Thule Chasm Duffel Large-Blue</DisplayName> 
      <Description>Thule Chasm Duffel Large in Blue.With a wide mouth opening and removable backpack straps these rugged, weather resistant duffels are your go-to gear hauler for any adventure.</Description> 
      <Widget1Url></Widget1Url> 
      <Widget2Url></Widget2Url> 
      <Widget3Url></Widget3Url> 
      <Tabs> 
       <Name>Product Information</Name> 
       <Description></Description> 
      </Tabs> 
      <SizeChartUrl></SizeChartUrl> 
      <SizeChartToolTip></SizeChartToolTip> 
      <PdfUrl></PdfUrl> 
      <PdfToolTip></PdfToolTip> 
      <SeoTitle>Thule Chasm Duffel Large-Blue</SeoTitle> 
     </LocalizedProductList> 

     <ServiceProviderUrl></ServiceProviderUrl> 
     <RewardCode>94</RewardCode> 
     <IsDiscountable>true</IsDiscountable> 
     <BrandImageURL>/19/BrandImage/thu.jpg</BrandImageURL> 
     <Activity>Traveller</Activity> 
    </Products> 
</ProductFile> 

但我得到以下結果。 enter image description here

當我刪除for-each語句它工作正常。有人讀過一些人說,爲每種方法有點混亂,http://gregbee.ch/blog/using-xsl-for-each-is-almost-always-wrong 我錯過了什麼?

+0

你的XML無法解析。請檢查 –

+1

在XSLT中沒有使用'xsl:for-each',特別是在你的非常簡單的情況下。否則,他們不會將其包含在語言規範中!用'xsl:for-each'來記住的主要事情是它根本不是一個「循環」,而是一個映射結構。 –

回答

2

沒有什麼錯誤使用xsl:for-each。您的方法存在的問題是:

<xsl:for-each select="ProductFile/Products"> 

將您置於Products的上下文中。從這裏,指令:

<xsl:value-of select="ProductFile/Products/Id"/> 

選擇什麼,因爲ProductFile不是Products一個孩子。你需要使用相對路徑Id,這簡直是:

<xsl:value-of select="Id"/> 

同樣的,你需要改變:

<xsl:value-of select="ProductFile/Products/LocalizedProductList/DisplayName"/> 

到:

<xsl:value-of select="LocalizedProductList/DisplayName"/> 
+0

這確實解釋得很好。謝謝! – Charl

2

您可以使用此:

    <xsl:for-each select="ProductFile/Products"> 
        <tr> 
         <td><xsl:value-of select="Id"/></td> 
         <td><xsl:value-of select="LocalizedProductList/DisplayName"/></td> 
        </tr> 
       </xsl:for-each> 
3
<xsl:for-each select="ProductFile/Products"> 
    <tr> 
    <td><xsl:value-of select="Id"/></td> 
    <td><xsl:value-of select="LocalizedProductList/DisplayName"/></td> 
    </tr> 
</xsl:for-each>