2013-10-10 3 views
0

mon nom de fichier xml est product_file.xml et j'ai un fichier xslt, j'utilise un contrôle xml dans ma page Web en liant xml & xslt fichiers au contrôle, mais je ne reçois pas le sortie correctement. Il ne montrant que tête plusieurs foisxslt avec le contrôle xml dans asp.net

<?xml version="1.0" encoding="utf-8" ?> 
<productlist> 
    <product> 
    <itemnumber>1</itemnumber> 
    <name>Staple Superior Men’s Jacket</name> 
    <description>The Staple Superior T-bone PU Jacket is classic hood with a drawstring  fastening, long and a zip up front fastening.</description> 
    <color>BLACK</color> 
    <image>Staplesuperior1.gif</image> 
    <price>$140</price> 
    <size>69</size> 
    <quantity>1</quantity> 
    <category>Men</category> 
    </product> 
    <product> 
    <itemnumber>2</itemnumber> 
    <name>Afends Mens t-shirt</name> 
    <description>The Afends Thrash For Cash Raglan Tee has a scooped hemline, a 100% cotton composition, and a regular fit.</description> 
    <color>Beach Heather &amp; Black</color> 
    <image>Afends1.gif</image> 
    <price>$90</price> 
    <size>80</size> 
    <quantity>1</quantity> 
    <category>Men</category> 
    </product> 
    <product> 
    <itemnumber>3</itemnumber> 
    <name>Wrangler Men Blue Vegas Skinny Fit Jeans</name> 
    <description>Blue 5 pocket jeans, stretchable, has a zip fly with buttoned closure in front, 2 scoop pockets at sides</description> 
    <image>Wrangler1.gif</image> 
    <color>BLUE</color> 
    <price>$125</price> 
    <size>32</size> 
    <quantity>1</quantity> 
    <category>Men</category> 
    </product> 
    <product> 
    <itemnumber>4</itemnumber> 
    <name>Roadster Women Top</name> 
    <description>Black top, knit, V neck, short extended sleeves, lattice like fabric manipulation detail at shoulders</description> 
    <color>BLACK</color> 
    <image>Roadster.gif</image> 
    <price>$55</price> 
    <size>Small</size> 
    <quantity>1</quantity> 
    <category>Women</category> 
    </product>  

et mon fichier xslt est

<xsl:template match="product">  
     <html> 
     <head> 
      <title>Products XSLT Demo</title> 
     </head> 
     <body> 
      <h2>Products Information</h2> 
      <br/>   
      <!--<xsl:copy> 
       <xsl:apply-templates select="@* | node()"/> 
      </xsl:copy>-->   
      <table bgcolor="#008BE7" border="1"> 
      <xsl:for-each select="itemnumber">    
      <tr> 
       <td>Item Number</td> 
       <td> 
       <xsl:value-of select="itemnumber"/> 
       </td> 
      </tr> 
      <tr> <td>name</td> 
       <td> 
       <xsl:value-of select="name"/> 
       </td> 
      </tr> 
      <tr> 
       <td>description</td> 
       <td> 
       <xsl:value-of select="description"/> 
       </td> 
      </tr> 
      <tr> 
       <td>color</td> 
       <td> 
       <xsl:value-of select="color"/> 
       </td> 
      </tr> 
      <tr> 
       <td>price</td> 
       <td> 
       <xsl:value-of select="price"/> 
       </td> 
      </tr> 
      <tr> 
       <td>size</td> 
       <td> 
       <xsl:value-of select="size"/> 
       </td> 
      </tr> 
      <tr> <td>quantity</td> 
       <td> 
       <xsl:value-of select="quantity"/> 
       </td> 
      </tr> 
      <tr> 
       <td>category</td> 
       <td> 
       <xsl:value-of select="category"/> 
       </td> 
      </tr> 
      </xsl:for-each> 
      </table>   
     </body> 
     </html> 
    </xsl:template> 
</xsl:stylesheet> 

maintenant l'erreur est l'expression foreach ne fonctionne pas si le ouput ne montrant que la position plusieurs fois

+0

ne doit pas être le foreach pour 'Product' au lieu de' itemnumber'? –

Répondre

0

Changer le foreach à

<xsl:for-each select="."> 
1

Cela semble fonctionner pour moi. changer le templatematch à productlist et foreach à product

<xsl:template match="productlist">  
     <html> 
     <head> 
      <title>Products XSLT Demo</title> 
     </head> 
     <body> 
      <h2>Products Information</h2> 
      <br/>   
      <!--<xsl:copy> 
       <xsl:apply-templates select="@* | node()"/> 
      </xsl:copy>-->   
      <table bgcolor="#008BE7" border="1"> 
      <xsl:for-each select="product">    
      <tr> 
       <td>Item Number</td> 
       <td> 
       <xsl:value-of select="itemnumber"/> 
       </td> 
      </tr> 
      <tr> <td>name</td> 
       <td> 
       <xsl:value-of select="name"/> 
       </td> 
      </tr> 
      <tr> 
       <td>description</td> 
       <td> 
       <xsl:value-of select="description"/> 
       </td> 
      </tr> 
      <tr> 
       <td>color</td> 
       <td> 
       <xsl:value-of select="color"/> 
       </td> 
      </tr> 
      <tr> 
       <td>price</td> 
       <td> 
       <xsl:value-of select="price"/> 
       </td> 
      </tr> 
      <tr> 
       <td>size</td> 
       <td> 
       <xsl:value-of select="size"/> 
       </td> 
      </tr> 
      <tr> <td>quantity</td> 
       <td> 
       <xsl:value-of select="quantity"/> 
       </td> 
      </tr> 
      <tr> 
       <td>category</td> 
       <td> 
       <xsl:value-of select="category"/> 
       </td> 
      </tr> 
      </xsl:for-each> 
      </table>   
     </body> 
     </html> 
    </xsl:template>