2011-09-29 26 views
0

请指教,注意XSLT转换。XSLT选择的变换值 - 空白输出?

我从以下XSLvalue-of中错过了什么?我有以下XML数据。然后在下面列出的我的转换中,我引用了这些元素,但在输出中获得了空字段。我必须使用在<xsl:value-of select="./userInfo/addressMap/entry[2]/firstName"/>

<userInfo> 
    <addressMap> 
     <entry> 
      <key>2</key> 
      <value> 
       <addressField1>21941 Main Drive</addressField1> 
       <addressField2>Apt XYZ</addressField2> 
       <addressType>0</addressType> 
       <city>Lake Forest</city> 
       <emailId>[email protected]</emailId> 
       <firstName>Krystal M</firstName> 
       <lastName>Obama</lastName> 
       <phoneNo>9495551212</phoneNo> 
       <state>CA</state> 
       <zipCode>92630</zipCode> 
      </value> 
     </entry> 
    </addressMap> 
</userInfo> 


    <table border="0" width="600" cellpadding="5" cellspacing="5"> 
    <tr bgcolor="#cccccc" style="font-size:14px; font-weight:bold;"> 
     <td align="left">SHIPPING INFO</td> 
     <td align="left">BILLING INFO</td> 
    </tr> 
    <tr bgcolor="#ffffff" style="font-size:12px;"> 
     <td align="left"><table border="0"> 
      <tr> 
      <td><xsl:value-of select="./userInfo/addressMap/entry[2]/firstName"/>&#160; 
      <xsl:value-of select="./userInfo/addressMap/entry[2]/lastName"/></td> 
      </tr> 
      <tr> 
      <td><xsl:value-of select="./userInfo/addressMap/entry[2]/addressField1"/></td> 
      </tr> 
      <xsl:choose> 
      <xsl:when test="./userInfo/addressMap/entry[2]/addressField2 and ./userInfo/addressMap/entry[2]/addressField2 != ''"> 
       <tr> 
       <td><xsl:value-of select="./userInfo/addressMap/entry[2]/addressField2"/></td> 
       </tr> 
      </xsl:when> 
      <xsl:otherwise> 
       <tr> 
       <td>&#32;</td> 
       </tr> 
      </xsl:otherwise> 
      </xsl:choose> 
      <tr> 
      <td><xsl:value-of select="./userInfo/addressMap/entry[2]/city"/>,&#160; 
      <xsl:value-of select="./userInfo/addressMap/entry[2]/state"/>&#160; 
      <xsl:value-of select="./userInfo/addressMap/entry[2]/zipCode"/> USA </td> 
      </tr> 
      <tr> 
      <td><xsl:value-of select="./userInfo/addressMap/entry[2]/phoneNo"/></td> 
      </tr> 
     </table> 

不正确的语法,这是我整个XML数据。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<cart> 
    <basketQuantity>0</basketQuantity> 
    <cartTotals> 
     <amtDueToBePaid>35.4</amtDueToBePaid> 
     <discountList>Employee Discount</discountList> 
     <giftWrapping>0.0</giftWrapping> 
     <preferredMemberAmountCharged>0.0</preferredMemberAmountCharged> 
     <preferredMemberSavings>0.0</preferredMemberSavings> 
     <promoCodeSavings>0.0</promoCodeSavings> 
     <promoShipping>0.0</promoShipping> 
     <regularMerchandise>59.0</regularMerchandise> 
     <regularShipping>0.0</regularShipping> 
     <saleMerchandise>59.0</saleMerchandise> 
     <savings>23.6</savings> 
     <shippingSavings>0.0</shippingSavings> 
     <subTotal>35.4</subTotal> 
     <tax>0.0</tax> 
     <taxableMerchandise>35.4</taxableMerchandise> 
     <total>35.4</total> 
    </cartTotals> 
    <errorAndWarnings/> 
    <itemsList> 
     <discountMap> 
      <entry> 
       <key>Employee Discount</key> 
       <value>23.6</value> 
      </entry> 
     </discountMap> 
     <itemName>Rosette Smocked Top</itemName> 
     <productId>45711923</productId> 
     <promoPrice>0.0</promoPrice> 
     <quantity>1</quantity> 
     <regularPrice>59.0</regularPrice> 
     <returnValue>35.4</returnValue> 
     <salePrice>59.0</salePrice> 
     <savings>23.6</savings> 
     <taxCode>0.0</taxCode> 
     <unitTax>0.0</unitTax> 
     <upc>457119500004</upc> 
     <uuid>b18ffa87c0a86f6f14618000479d92c9</uuid> 
    </itemsList> 
    <orderPlaced>false</orderPlaced> 
    <pipelineSessionId>abcxyz</pipelineSessionId> 
    <shipping> 
     <availableShippingMap> 
      <entry> 
       <key>2</key> 
       <value> 
        <actualShippingCost>7.95</actualShippingCost> 
        <deliveryDays>0</deliveryDays> 
        <savings>0.0</savings> 
        <shippingDiscount>0.0</shippingDiscount> 
        <shippingMethodName>2nd Day</shippingMethodName> 
       </value> 
      </entry> 
      <entry> 
       <key>1</key> 
       <value> 
        <actualShippingCost>0.0</actualShippingCost> 
        <deliveryDays>0</deliveryDays> 
        <savings>0.0</savings> 
        <shippingDiscount>0.0</shippingDiscount> 
        <shippingMethodName>Standard Shipping</shippingMethodName> 
       </value> 
      </entry> 
      <entry> 
       <key>3</key> 
       <value> 
        <actualShippingCost>19.95</actualShippingCost> 
        <deliveryDays>0</deliveryDays> 
        <savings>0.0</savings> 
        <shippingDiscount>0.0</shippingDiscount> 
        <shippingMethodName>Overnight Delivery</shippingMethodName> 
       </value> 
      </entry> 
     </availableShippingMap> 
     <savings>0.0</savings> 
     <selectedShippingMethodId>1</selectedShippingMethodId> 
     <shippingCost>0.0</shippingCost> 
     <shippingPromo>0.0</shippingPromo> 
    </shipping> 
    <userInfo> 
     <addressMap> 
      <entry> 
       <key>2</key> 
      <value> 
       <addressField1>21941 Main Drive</addressField1> 
       <addressField2>Apt XYZ</addressField2> 
       <addressType>0</addressType> 
       <city>Lake Forest</city> 
       <emailId>[email protected]</emailId> 
       <firstName>Krystal M</firstName> 
       <lastName>Obama</lastName> 
       <phoneNo>9495551212</phoneNo> 
       <state>CA</state> 
       <zipCode>92630</zipCode> 
      </value> 
      </entry> 
     </addressMap> 
    </userInfo> 
</cart> 
+0

用于运行转换的处理器是什么?我可以通过Visual Studio 2010成功运行此顶级获取此输出 - http://jsbin.com/ulibel/2/edit –

+0

我正在使用Eclipse XSLT处理器 – Byron

+0

什么是您使用'xsl:价值的'在?另外,您正在寻找''中的第二个'',但在您的示例中只有1个''。 –

回答

1

问题是“entry [2]”,它没有按照您的意愿选择带有键2的条目。

关闭我的头顶,应该是“./userInfo/addressMap/entry[string(key)= 2]/value/firstName”。

+0

谢谢@Dabbler,解决了我的问题。 – Byron