문제

Axis2와 Ajax 문제가 발생합니다. jQuery의 Ajax 함수가있는 웹 서비스 중 하나에서 XML을 사용하고 사용하고 있습니다. 이것 jQuery 플러그인 결과 XML을 HTML로 변환합니다.

다음은 서비스가 반환하는 관련 XML의 예입니다.

<ns:getPatientsByDoctorResponse>
    <ns:return type="com.emolst.jdbc.PatientBean">
        <ax23:firstName>Bryce</ax23:firstName>
        <ax23:lastName>Thompson</ax23:lastName>
    </ns:return>
</ns:getPatientsByDoctorResponse>

jQuery ajax 호출에서 얻은 XML 문서 객체를 살펴 보았고 태그에서 네임 스페이스를 제거하고 태그를 모두 소문자로 만들었습니다. 그러나 XSL 템플릿이 태그를 인식하기 위해 얻을 수없는 것 같습니다.

다음은 XSL에서 내가 지금 가지고있는 것입니다.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="//return">
        <option>success2</option>
        <option>
            <xsl:value-of select="firstname"/> <xsl:value-of select="lastname"/>
        </option>
    </xsl:template>
</xsl:transform>

내가 얻을 수있는 최선은 성공 1 옵션입니다. 정보를 찾았습니다 여기 Axis2가 Ajax와 더 잘 플레이하는 것에 대해, 그러나 그것은 내가 가진 Java 서비스 클라이언트를 망칠 수있는 것처럼 보입니다.

문제의 JavaScript는 다음과 같습니다.

$("select[name=patientlist]").transform({
    xml:{
        url:"/axis2/services/PatientService/getPatientsByDoctor",
        data {
            docKey: "6"
        },
        type:"GET",
        dataType:"xml"
    },
    xsl:"xsl/patients-option.xsl"
});

그래서 나는 바보 같은 일을하고 있습니까, 아니면 더 좋은 방법이 있습니까? 도움을 주셔서 감사합니다.

도움이 되었습니까?

해결책

당신은 네임 스페이스가 사라 졌다고 생각하지만 나는 그렇지 않다고 생각합니다. 왜 그렇게해야합니까?

다음과 같은 네임 스페이스를 무시하는 변환을 시도하십시오.

<xsl:transform 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="//*[local-name()='return']">
        <option>success2</option>
        <option>
            <xsl:value-of select="*[local-name()='firstname']"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="*[local-name()='lastname']"/>
        </option>
    </xsl:template>

</xsl:transform>

또는 다음과 같이 올바르게 사용하는 템플릿.

<xsl:transform 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ax23="........ax23 namespace here........"
  xmlns:ns="........ns namespace here........"
>

    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <option>success1</option>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="ns:return">
        <option>success2</option>
        <option>
            <xsl:value-of select="ax23:firstname"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="ax23:lastname"/>
        </option>
    </xsl:template>

</xsl:transform>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top