开发者

XSLT Transformation value of select - Blank output?

Please advise, noob to XSLT transformation.

What am I missing from the following XSLvalue-of? I have the following XML data. Then in my transformation listed below I am referencing these elements but I get empty fields in my output. I must be using the incorrect syntax on the <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-weigh开发者_StackOverflowt: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>

Here is my entire xml data.

<?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>


The problem is the "entry[2]", it's not selecting the entry with key 2 as you intend it to.

Off the top of my head, that should be something like "./userInfo/addressMap/entry[string(key) = 2]/value/firstName".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜