我正在与Axis2和AJAX的问题。我从jQuery的AJAX功能,我的Web服务的一个获取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>

我是通过XML文档对象,我从jQuery AJAX调用衣服看上去,它似乎已经剥去标签的命名空间和取得的标签全部小写。不过,我似乎无法让我的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选项。我发现了一些信息这里有关使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