0

I could not able to access PartNumber/Description value under attribute tag with below xpath but and soap xml is given below.Let me know any further details required.

Please help on this.Thanks inadvance!.

Xpath being used And SOAP XML Message:

<xsl:value-of select="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='PullCustomerPartsPricingResponse']/*[local-name()='PullCustomerPartsPricingResult']/*[local-name()='CustomerPart']/@*[local-name()='PartNumber']"/> 


<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <s:Header />
   <s:Body>
      <PullCustomerPartsPricingResponse xmlns="http://cdx.dealerbuilt.com/Api/0.99/">
         <PullCustomerPartsPricingResult xmlns:a="http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:CustomerPart>
               <a:Placement>
                  <a:GroupId>10</a:GroupId>
               </a:Placement>
               <a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/DealerBuilt.Models.Parts">
                  <b:AddedDate>2017-12-19T00:00:00</b:AddedDate>
                  <b:DealerPartId>287925</b:DealerPartId>
                  <b:Description>BAT (51/500AMP85)</b:Description>
                  <b:PartNumber>31500SB2yy1M</b:PartNumber>
                  <b:QuantityLostMonthToDate>0</b:QuantityLostMonthToDate>
               </a:Attributes>
               <a:PartKey>GZ287925</a:PartKey>
               <a:CustomerListPrice xmlns:b="http://schemas.datacontract.org/2004/07/DealerBuilt.Models">
                  <b:Amount>130.49</b:Amount>
                  <b:Currency>UsDollar</b:Currency>
               </a:CustomerListPrice>
            </a:CustomerPart>
         </PullCustomerPartsPricingResult>
      </PullCustomerPartsPricingResponse>
   </s:Body>
</s:Envelope>

Regards Vardhan

vardhanm9
  • 11
  • 2
  • Namespaces are to be used, not avoided. See; https://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 – michael.hor257k Jan 31 '19 at 09:51

2 Answers2

0

You have ended your long xpath expression with this..

/@*[local-name()='PartNumber']

But PartNumber is not an attribute. It is an element named PartNumber that is a child of an element that happened to be named Attributes, but that does not actually make it an attribute in XML terms!

It should look like this...

<xsl:value-of select="/*[local-name()='Envelope']
                        /*[local-name()='Body']
                        /*[local-name()='PullCustomerPartsPricingResponse']
                        /*[local-name()='PullCustomerPartsPricingResult']
                        /*[local-name()='CustomerPart']
                        /*[local-name()='Attributes']
                        /*[local-name()='PartNumber']"/> 

Although it would be really better if you declared the namespaces in your XSLT and used then in your xpath.

Tim C
  • 70,053
  • 14
  • 74
  • 93
0

NameSpaces from the request XML need to be used in xslt as well.Following xsl gave the PartNumber value.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:a="http://schemas.datacontract.org/2004/07/DealerBuilt.BaseApi" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:b="http://schemas.datacontract.org/2004/07/DealerBuilt.Models.Parts">
    <xsl:output method="xml" version="1.0"/>
    <xsl:template match="/">
        <xsl:value-of select="*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='PullCustomerPartsPricingResponse']/*[local-name()='PullCustomerPartsPricingResult']/*[local-name()='CustomerPart']/*[local-name()='Attributes']/*[local-name()='PartNumber']"/>
    </xsl:template>
</xsl:stylesheet>
harish
  • 15
  • 2