xslt:通配符条件检查并使用通配符读取值

时间:2016-07-14 13:23:32

标签: xpath xslt-1.0

将xml输入到XSLT 1.0

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <MESSAGE xmlns="http://MessangerApplication/datamodel">
            <LAST_UPDATED_BY>-2</LAST_UPDATED_BY>
            <LAST_UPDATE_DATE>2016-07-13T15:02:34.000-07:00</LAST_UPDATE_DATE>
            <PREV_MODIFIED_DATE_ACC_CONTACT_IN_CUSTOM_TABLE>2016-07-13T15:02:34.000-07:00</PREV_MODIFIED_DATE_ACC_CONTACT_IN_CUSTOM_TABLE>
            <ADDRESSES>
                <ADDRESS>
                    <ADDR_ID>-10197894</ADDR_ID>
                    <LAST_UPDATED_BY>-2</LAST_UPDATED_BY>
                    <LAST_UPDATE_DATE>2016-07-13T15:54:19.000-07:00</LAST_UPDATE_DATE>
                    <PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE/>
                </ADDRESS>
                <ADDRESS>
                    <LAST_UPDATED_BY>5309</LAST_UPDATED_BY>
                    <LAST_UPDATE_DATE>2016-07-13T15:55:32.000-07:00</LAST_UPDATE_DATE>
                    <PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE>2016-07-13T16:53:21.000-07:00</PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE>
                </ADDRESS>
                <ADDRESS>
                    <LAST_UPDATED_BY>5309</LAST_UPDATED_BY>
                    <LAST_UPDATE_DATE>2016-07-13T15:55:32.000-07:00</LAST_UPDATE_DATE>
                    <PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE>2016-07-13T15:06:12.000-07:00</PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE>
                </ADDRESS>
            </ADDRESSES>
            <PHONES>
                <PHONE>
                    <LAST_UPDATED_BY>-2</LAST_UPDATED_BY>
                </PHONE>
            </PHONES>
        </MESSAGE>
    </soapenv:Body>
</soapenv:Envelope>
下面的

是我的XSLT

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://MessangerApplication/datamodel">
        <xsl:template match="//ns:MESSAGE">
            <ns:Account_Address>
<!-- START : First choose block -->
                <xsl:choose>
                    <xsl:when
                        test="(('-2' != ns:LAST_UPDATED_BY or '-2' != ns:PHONES/ns:PHONE/ns:LAST_UPDATED_BY) and 
                        (ns:PREV_MODIFIED_DATE_ACC_CONTACT_IN_CUSTOM_TABLE != ''))">
                        <xsl:variable name="currentDate" select="ns:LAST_UPDATE_DATE"/>
                        <xsl:variable name="prevDate" select="ns:PREV_MODIFIED_DATE_ACC_CONTACT_IN_CUSTOM_TABLE"/>

                        <testingAccount>true</testingAccount>

                    </xsl:when>
                    <xsl:otherwise>
                        <testingAccount>false</testingAccount>
                    </xsl:otherwise>
                </xsl:choose>
<!-- END : First choose block -->     
**<!-- START : Second choose block -->**           
                <xsl:choose>
                    <xsl:when
                        test="((ns:ADDRESSES/ns:ADDRESS[ns:LAST_UPDATED_BY] != '-2') and 
                        (ns:ADDRESSES/ns:ADDRESS[ns:PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE != '']))">
                        <!-- 
                            here i want to read LAST_UPDATE_DATE and PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE
                        -->
                    </xsl:when>
                    <xsl:otherwise>
                        <addressTesting>false</addressTesting>
                    </xsl:otherwise>
                </xsl:choose>
**<!-- END : Second choose block -->**
            </ns:Account_Address>
        </xsl:template>
    </xsl:stylesheet>

所以在XSLT(第二个选择块)中我想读下面的值并在找到下面两个标签的值时停止进一步遍历

1) LAST_UPDATE_DATE (path : ADDRESSES/LAST_UPDATE_DATE)
2) PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE (path : ADDRESSES/PREV_MODIFIED_DATE_ADDR_IN_CUSTOM_TABLE)

enter image description here

请建议我如何在第二个选择块(在XSLT中提到)中实现逻辑,非常感谢

我正在使用XSLT 1.0

0 个答案:

没有答案