xmlxsltshopifynestedxml-formatting

XSL Selecting A Nested Field (From Shopify XML Output)


I'm formatting a Shopify output XML file and need to select the first-name field, however they have multiple, nested, first-name fields. How do I go about selecting one?

<order>
    <billing-address type="Address">
        <first-name>Bob</first-name>
        <last-name>Biller</last-name>
    </billing-address>
    <shipping-address type="Address">
        <first-name>Steve</first-name><!-- Trying to select shipping-address >> first-name -->
        <last-name>Shipper</last-name>
    </shipping-address>
</order>

Solution

  • Not sure about the template you are using for this, but as example if you have a template matching the whole order:

    <xsl:template match="order">  
      First name: <xsl:value-of select="shipping-address/first-name"/>
      Last name: <xsl:value-of select="shipping-address/last-name"/>
    </xsl:template>
    

    has the result

    First name: Steve
    Last name: Shipper