2011-03-15 33 views
0

如何在下面的XML使用XSLT檢索XML的某些節點,如果節點具有名稱空間,則會出現問題。

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <SOAP-ENV:Body> 
     <rpc:ConQueryByExampleResponse 
      xmlns:rpc="http://siebel.com/asi/"> 
      <SiebelMessage> 
       <ListOfContactInterfaceMobile 
        xmlns="http://www.siebel.com/xml/Contact%20Interface%20Mobile"> 
        <Contact> 
         <FirstName>Siebel</FirstName> 
         <JobTitle>Sys Admin</JobTitle> 
         <LastName>Administrator</LastName> 
         <PersonUId>0-1</PersonUId> 
         <PersonalContact>Nva</PersonalContact> 
         <PrimaryOrganization>dga</PrimaryOrganization> 
        </Contact> 
        <Contact> 
         <FirstName>xyz</FirstName> 
         <JobTitle>Sn</JobTitle> 
         <LastName>Admin</LastName> 
         <PersonUId>0-2</PersonUId> 
         <PersonalContact>Nar</PersonalContact> 
         <PrimaryOrganization>adfg</PrimaryOrganization> 
        </Contact> 
       </ListOfContactInterfaceMobile> 
      </SiebelMessage> 
     </rpc:ConQueryByExampleResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 
+0

[在PHP SimpleXML對象上使用xpath,SOAP +名稱空間(不工作..)](http://stackoverflow.com/questions/3864359/using-xpath-on-a-php-simplexml- object-soap-namespaces-not-working) – 2011-03-15 14:43:51

回答

3
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:rpc="http://siebel.com/asi/" 
    xmlns:siebel="http://www.siebel.com/xml/Contact%20Interface%20Mobile"> 
    <xsl:template match="/"> 
     <xsl:apply-templates select=" 
      SOAP-ENV:Envelope/SOAP-ENV:Body/ 
      rpc:ConQueryByExampleResponse/SiebelMessage/ 
      siebel:ListOfContactInterfaceMobile/siebel:Contact/siebel:FirstName 
      "/> 
    </xsl:template> 
</xsl:stylesheet> 

結果將是Siebelxyz檢索使用命名空間的名字。

只是googlexpath default namespace,這是有史以來最常見的FAQ。

+0

+1得到正確的答案。 – 2011-03-15 14:29:44

相關問題