2016-08-11 5 views
0

는 XML :헨델 네임 스페이스 - XSLT

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<soap:Body> 
    <GetDataResponse xmlns="http://example.com/webservices/"> 
    <GetDataResult> 
     <diffgr:diffgram xmlns:msdata="urn:schemas-abc-com:xml-msdata" xmlns:diffgr="urn:schemas-abc-com:xml-diffgram-v1"> 
      <CompListData xmlns=""> 
       <Table diffgr:id="Table1" msdata:rowOrder="0" diffgr:hasChanges="inserted"> 
       <Comp>JL-C</Comp> 
       <Type>JOB</Type> 
       <Cost>Lakhs</Cost> 
       </Table> 
       <Table diffgr:id="Table2" msdata:rowOrder="1" diffgr:hasChanges="inserted"> 
       <Comp>JL-C1</Comp> 
       <Type>JOB1</Type> 
       <Cost>Lakhs</Cost> 
       </Table> 
      </CompListData> 
     </diffgr:diffgram> 
    </GetDataResult> 
    </GetDataResponse> 
</soap:Body> 
</soap:Envelope> 

XSLT : 출력 메신저 점점

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
exclude-result-prefixes="s xsi xsd "> 
<xsl:output method="xml" indent="yes"></xsl:output> 
<xsl:strip-space elements="*" /> 
<xsl:template match="/"> 

    <xsl:if test="s:Envelope/s:Body/GetDataResponse/GetDataResult/diffgr/CompListData/TableTable[@id='Table1']/Type"> 
     <JobType1> 
      <xsl:value-of 
       select="s:Envelope/s:Body/GetDataResponse/GetDataResult/diffgr/CompListData/TableTable[@id='Table1']/Type"></xsl:value-of> 
     </JobType1> 
    </xsl:if> 
<xsl:if test="s:Envelope/s:Body/GetDataResponse/GetDataResult/diffgr/CompListData/TableTable[@id='Table2']/Type"> 
     <JobType2> 
      <xsl:value-of 
       select="s:Envelope/s:Body/GetDataResponse/GetDataResult/diffgr/CompListData/TableTable[@id='Table2']/Type"></xsl:value-of> 
     </JobType2> 
    </xsl:if> 
</xsl:template> 
</xsl:stylesheet> 

는 XSLT의 첫 번째 줄입니다

<?xml version="1.0" encoding="UTF-8"?> 

누군가가 body 내에서 'diffgr : diffgram'을 처리하고 'JobType'태그에 'Type'값을 가져 오는 방법을 안내해 줄 수 있습니까? GetDataResponse, GetDataResultdiffgram 요소의 네임 스페이스를 무시 주로뿐만 아니라 그의 id 속성 -

답변

1

귀하의 XPath 식은 여러 가지 결함을 가지고있다.

또한 diffgram 대신 diffgr, Table 대신 TableTable을 썼습니다.

대신보십시오 :

XSLT

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:w="http://example.com/webservices/" 
xmlns:d="urn:schemas-abc-com:xml-diffgram-v1" 
exclude-result-prefixes="s w d"> 
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> 

<xsl:template match="/"> 
    <xsl:variable name="jobtype1" select="s:Envelope/s:Body/w:GetDataResponse/w:GetDataResult/d:diffgram/CompListData/Table[@d:id='Table1']/Type" /> 
    <xsl:variable name="jobtype2" select="s:Envelope/s:Body/w:GetDataResponse/w:GetDataResult/d:diffgram/CompListData/Table[@d:id='Table2']/Type" /> 
    <xsl:if test="$jobtype1"> 
     <JobType1> 
      <xsl:value-of select="$jobtype1"/> 
     </JobType1> 
    </xsl:if> 
    <xsl:if test="$jobtype2"> 
     <JobType2> 
      <xsl:value-of select="$jobtype2"/> 
     </JobType2> 
    </xsl:if> 
</xsl:template> 

</xsl:stylesheet> 

1.0 여기선 생산 결과가 잘 구성된 XML 문서 (아무 단일 루트 요소가) 아니라고.

+0

감사합니다. 솔직히 말해서, 틀림없이 많은 실수가 있었고, 네임 스페이스 – Ranjan

관련 문제