选择的XSLT转换值 - 空白输出?

时间:2011-09-29 15:50:02

标签: xslt xpath

请告知,noob进行XSLT转换。

我在以下XSLvalue中缺少什么?我有以下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>krystal@bogus.com</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>krystal@bogus.com</emailId>
                <firstName>Krystal M</firstName>
                <lastName>Obama</lastName>
                <phoneNo>9495551212</phoneNo>
                <state>CA</state>
                <zipCode>92630</zipCode>
            </value>
            </entry>
        </addressMap>
    </userInfo>
</cart>

1 个答案:

答案 0 :(得分:1)

问题是“输入[2]”,它没有像你想要的那样选择带有键2的条目。

在我的脑海中,应该是“./userInfo/addressMap/entry[string(key)= 2] / value / firstName”。