使用 XSLT 检索 XML 的某些节点,如果节点具有名称空间,则会出现问题。!

发布于 2024-10-22 04:08:16 字数 1755 浏览 1 评论 0原文

如何使用以下 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>

how to retrieve the first names using namespaces in the following 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2024-10-29 04:08:16
<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

只是 google xpath 默认命名空间< /code>,这是有史以来最多的常见问题解答。

<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>

Result will be Siebelxyz.

Just google xpath default namespace, it's the most FAQ ever.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文