2017-05-07 11 views
0

xslと.cssのxml文書があります。私は結果を得るが、custIDごとに1つの行を取得する代わりに、それぞれ1行ずつ取得しますが、各行にすべての顧客が含まれています。私が間違っていることを確信していない。 --- XSLお客様ごとに1行ではなく、すべての行が繰り返し表示されます

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" 
     doctype-system="about:legacy-compat" 
     encoding="UTF-8" 
     indent="yes" /> 

    <xsl:param name="customerID" select="//@custID"/> 
    <xsl:variable name="reportCustomer" 
    select="document('customers.xml')/customers/customer[@custID=$customerID]" /> 

    <xsl:template match="/"> 
     <html> 
     <head> 
      <title>Customer List</title> 
      <link href="customersAgain.css" rel="stylesheet" type="text/css" /> 
     </head> 

     <body> 
      <div id="wrap"> 

       <h1>Customers</h1> 

<!-- <xsl:for-each select = "$customerID"> --> 

       <table id="customerTable"> 
        <tr> 
        <th>CustID</th> 
        <th>Cust FName</th> 
        <th>Cust LName</th>      
        <th>Address</th> 
        <th>Phone</th> 
        <th>Email</th> 
        </tr> 
<xsl:for-each select = "$customerID">   
        <tr> 
        <td> 
         <xsl:value-of select="$customerID" /> 
        </td>    
        <td> 
         <xsl:value-of select="$reportCustomer/first_name" /> 
        </td> 
        <td> 
         <xsl:value-of select="$reportCustomer/last_name" /> 
        </td> 
        <td> 
         <xsl:value-of select="$reportCustomer/street" /><br /> 
         <xsl:value-of select="$reportCustomer/city" />, 
         <xsl:value-of select="$reportCustomer/state" /> 
         <xsl:value-of select="$reportCustomer/zip" /> 
        </td> 
        <td> 
         <xsl:value-of select="$reportCustomer/phone" /> 
        </td> 
        <td> 
         <xsl:value-of select="$reportCustomer/email" /> 
        </td> 
        </tr> 
        <xsl:apply-templates select="customers/customer[@custID=$customerID]" /> 
</xsl:for-each>    
       </table> 

      <!--  <xsl:apply-templates select="customers/customer[@custID=$customerID]" /> 
</xsl:for-each> --> 
      </div> 
     </body> 
     </html> 
    </xsl:template> 
</xsl:stylesheet> 

---- XMLとして結果をお探し

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="customersAgain.xsl" ?> 
<customers xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
      xs:noNamespaceSchemaLocation="customers.xsd"> 
    <customer custID = "cust10001"> 
     <first_name>Mina</first_name> 
     <last_name>Talver</last_name> 
     <street>1121 Huntington Road</street> 
     <city>Morehead</city> 
     <state>SD</state> 
     <zip>52541</zip> 
     <phone>(252) 123-8444</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10002"> 
     <first_name>Joe</first_name> 
     <last_name>Crater</last_name> 
     <street>526 Corona Lane</street> 
     <city>Raleigh</city> 
     <state>SC</state> 
     <zip>52615</zip> 
     <phone>(506) 123-5124</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10003"> 
     <first_name>Linda</first_name> 
     <last_name>bigby</last_name> 
     <street>74 Center Court</street> 
     <city>Spaeder</city> 
     <state>AL</state> 
     <zip>85947</zip> 
     <phone>(885) 123-5156</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10004"> 
     <first_name>Bradley</first_name> 
     <last_name>Goetzman</last_name> 
     <street>552 Walker Street</street> 
     <city>Biloxy</city> 
     <state>MA</state> 
     <zip>52361</zip> 
     <phone>(852) 123-2252</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10005"> 
     <first_name>Donna</first_name> 
     <last_name>Lipsky</last_name> 
     <street>954 Mannard Way</street> 
     <city>Carhart</city> 
     <state>FL</state> 
     <zip>52398</zip> 
     <phone>(954) 123-6251</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10006"> 
     <first_name>Heath</first_name> 
     <last_name>Braden</last_name> 
     <street>58 East State Street</street> 
     <city>Silo Rapids</city> 
     <state>MN</state> 
     <zip>52632</zip> 
     <phone>(232) 123-8545</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10007"> 
     <first_name>Charisma</first_name> 
     <last_name>Wingard</last_name> 
     <street>45 Beverly Way</street> 
     <city>Paris</city> 
     <state>TX</state> 
     <zip>75858</zip> 
     <phone>(856) 123-7458</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10008"> 
     <first_name>Drake</first_name> 
     <last_name>Sorento</last_name> 
     <street>332 Kia Street</street> 
     <city>Carrito</city> 
     <state>NM</state> 
     <zip>55636</zip> 
     <phone>(864) 123-4565</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10009"> 
     <first_name>Jessica</first_name> 
     <last_name>Denon</last_name> 
     <street>562 Arthur Circle</street> 
     <city>Oak Tree</city> 
     <state>WY</state> 
     <zip>88787</zip> 
     <phone>(123) 123-5262</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10010"> 
     <first_name>Becky</first_name> 
     <last_name>Newton</last_name> 
     <street>45 North Avenue</street> 
     <city>Capitulo</city> 
     <state>TX</state> 
     <zip>55698</zip> 
     <phone>(415) 123-5445</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10011"> 
     <first_name>Rodger</first_name> 
     <last_name>Comancho</last_name> 
     <street>852 Leaf Boulevard</street> 
     <city>Warren</city> 
     <state>OK</state> 
     <zip>63589</zip> 
     <phone>(777) 123-2052</phone> 
     <email>[email protected]</email> 
    </customer> 
    <customer custID = "cust10012"> 
     <first_name>Mike</first_name> 
     <last_name>Doger</last_name> 
     <street>63 willingsway Drive</street> 
     <city>Saint Aug</city> 
     <state>CA</state> 
     <zip>36258</zip> 
     <phone>(121) 123-1221</phone> 
     <email>[email protected]</email> 
    </customer> 
</customers> 

:ホープ誰かが助けることができる 上

CustID  Cust FName Cust LName Address       Phone  Email 
cust10001 Mina  Talver  1121 Huntington Road, Morehead, SD 52541 (252) 123-8444 [email protected] 

cust10002 Joe Crater 526 Corona Lane, Raleigh, SC 52615 (506) 123-5124 [email protected] 

ので!あなたは

答えて

1

、変更する必要がありますありがとう:

<xsl:value-of select="$reportCustomer/first_name" /> 

へ:ように

<xsl:value-of select="../first_name" /> 

と。それ以外の場合は、$reportCustomer文書のルートからすべてのfirst_nameノードを選択しています。代わりに現在の顧客のデータへの相対パスを使用します。


P.S.私はcustomer[@custID=$customerID]の条件が成し遂げられるべきものが何であるか分かりません - それはいつも真実です。あるいは、なぜXML入力で直接作業するのではなく、document()関数を使用する必要があるのでしょうか。

また、この行は理にかなっていない(そして幸運にもいずれかの他に何もしない)、少なくともない@custIDのコンテキストで:

<xsl:apply-templates select="customers/customer[@custID=$customerID]" /> 

私はあなたのような何かにあなたのスタイルシートを簡素化することができると思います:

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

<xsl:template match="/customers"> 
    <html> 
     <head> 
      <title>Customer List</title> 
      <link href="customersAgain.css" rel="stylesheet" type="text/css" /> 
     </head> 
     <body> 
      <div id="wrap"> 
       <h1>Customers</h1> 
       <table id="customerTable"> 
        <tr> 
         <th>CustID</th> 
         <th>Cust FName</th> 
         <th>Cust LName</th> 
         <th>Address</th> 
         <th>Phone</th> 
         <th>Email</th> 
        </tr> 
        <xsl:for-each select="customer"> 
         <tr> 
          <td> 
           <xsl:value-of select="@custID" /> 
          </td> 
          <td> 
           <xsl:value-of select="first_name" /> 
          </td> 
          <td> 
           <xsl:value-of select="last_name" /> 
          </td> 
          <td> 
           <xsl:value-of select="street" /> 
           <br /> 
           <xsl:value-of select="city" /> 
           <xsl:text>, </xsl:text> 
           <xsl:value-of select="state" /> 
           <xsl:text> </xsl:text> 
           <xsl:value-of select="zip" /> 
          </td> 
          <td> 
           <xsl:value-of select="phone" /> 
          </td> 
          <td> 
           <xsl:value-of select="email" /> 
          </td> 
         </tr> 
        </xsl:for-each> 
       </table> 
      </div> 
     </body> 
    </html> 
</xsl:template> 

</xsl:stylesheet> 
関連する問題