2017-06-20 34 views
0

我試圖找到「lucidId」在這個SOAP回報的XPath:當我把我的XPath「迴歸」試圖找到XPATH

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://media.com/entities/lpedition" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <SOAP-ENV:Body> 
     <ns1:detailFromPublicationDateResponse> 
      <return SOAP-ENC:arrayType="ns1:Edition[2]" xsi:type="ns1:EditionArray"> 
      <item id="5267" status="" adsBundleStatus="" adsBundleSizeInBytes="" adsBundleUrl="" xsi:type="ns1:Edition" xmlns="http://lapresse.ca/entities/lpedition"> 
       <name>ARTS CINÉMA</name> 
       <publishedAt>20170603</publishedAt> 
       <sections> 
        <section id="22556" type="CAT" rank="1"> 
         <typeCode>REG</typeCode> 
         <color>008591</color> 
         <name>ARTS CINÉMA</name> 
         <pages> 
         <page id="66972270" lucidId="3d84e764-c507-4f07-82c3-c6f9cab588eb|_0" pageNumberForEdition="" pageNumberForSection="1" type="" adsBundleStatus="" adsBundleSizeInBytes="0" adsBundleUrl=""> 
          <navThumbnail url="http://lp-bo.lapresse.ca/api/5267/d8eb9c12f7b449dd80bf852832638ed7/thumbnail-nav"> 
           <title>À la une</title> 
           <subTitle>ARTS</subTitle> 
          </navThumbnail> 
          <screenCapture url="http://lp-bo.lapresse.ca/api/5267/d8eb9c12f7b449dd80bf852832638ed7/thumbnail?lucidRank=0"/> 
          <ads/> 
          <pages/> 
          <articles/> 
          <slideshows/> 
         </page> 

,我沒有得到任何

/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:detailFromPublicationDateResponse/return 

我嘗試過使用各種xpath測試程序,並且我沒有收到任何東西...... 是否必須對數組做任何事情?

它在我正在做的時候對xpath有效://pages/page/@lucidId 但是在我的XSL文件中,我無法繞過return

這就是我要做的:

<xsl:template match="/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:detailFromPublicationDateResponse/return"> 
    <xsl:for-each select="item/sections/section/pages/page"> 
    <xsl:value-of select="@lucidId"/><xsl:text>;</xsl:text> 
+0

你嘗試'//網頁/網頁/ @ lucidId'? – SomeDude

+0

我做到了,但是當我嘗試在我的XSL中使用它時,它不會返回任何東西... – sboivin

+2

'item'下的所有內容都位於默認命名空間'http:// lapresse.ca/entities/lpedition'中。嘗試將該名稱空間綁定到XSLT中的前綴,然後在xpath中使用它。 –

回答

-1
/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='detailFromPublicationDateResponse']/*[local-name()='return']/*[local-name()='item']/*[local-name()='sections']/*[local-name()='section']/*[local-name()='pages']/*[local-name()='page']/@lucidId 

或只是

//*[local-name()='pages']/*[local-name()='page']/@lucidId 
+0

這不是一個好建議。名稱空間將被使用,不會被忽略。 –

0

一切從item下是默認的命名空間http://lapresse.ca/entities/lpedition

嘗試將該名稱空間綁定到XSLT中的前綴並在xpath中使用它。

在下面的示例中,我將名稱空間綁定到前綴lp

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns1="http://media.com/entities/lpedition" 
    xmlns:lp="http://lapresse.ca/entities/lpedition" 
    exclude-result-prefixes="SOAP-ENV ns1 lp"> 
    <xsl:output indent="yes" omit-xml-declaration="yes"/> 
    <xsl:strip-space elements="*"/> 

    <xsl:template match="/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:detailFromPublicationDateResponse/return"> 
    <xsl:for-each select="lp:item/lp:sections/lp:section/lp:pages/lp:page"> 
     <xsl:value-of select="@lucidId"/><xsl:text>;</xsl:text> 
    </xsl:for-each> 
    </xsl:template> 

</xsl:stylesheet> 

輸出

3d84e764-c507-4f07-82c3-c6f9cab588eb|_0;