jQueryとAJAXを使用してaxis2サービスからxmlを変換するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/656459

質問

axis2とajaxで問題が発生しています。 jQueryのajax関数を使用してWebサービスの1つからxmlを取得し、 this 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 Documentオブジェクトを調べましたが、タグから名前空間を取り除き、タグをすべて小文字にしたようです。ただし、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>

私が得ることができる最高のものはsuccess1オプションです。 Ajaxでaxis2をより快適に再生する方法についてこちらを見つけましたが、私が持っている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