我需要使用XSLT(版本1不幸)..我試圖通過比較子節點中的兩個屬性來過濾某些節點。XSLT過濾器比較同一子節點中的兩個值
這裏是XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
</SOAP-ENV:Header>
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<QueriesResponse xmlns="http://schemas.Movies.com/Movies">
<Films xmlns="http://schemas.Movies.com/Movies">
<Film>
<FilmPostings>
<FilmPosting>
<FilmPostingDates>
<FilmPostDate>2017-01-04T19:44:25.9530000-05:00</FilmPostDate>
<FilmActiveDate>2017-01-04T19:44:25.9530000-05:00</FilmActiveDate>
</FilmPostingDates>
</FilmPosting>
</FilmPostings>
</Film>
<Film>
<FilmPostings>
<FilmPosting>
<FilmPostingDates>
<FilmPostDate>2017-01-04T19:50:06.3830000-05:00</FilmPostDate>
<FilmActiveDate>2017-01-04T19:50:06.3100000-05:00</FilmActiveDate>
</FilmPostingDates>
</FilmPosting>
</FilmPostings>
</Film>
<Film>
<FilmPostings>
<FilmPosting>
<FilmPostingDates>
<FilmPostDate>2016-12-05T18:03:14.9830000-05:00</FilmPostDate>
<FilmActiveDate>2017-01-02T00:16:52.7570000-05:00</FilmActiveDate>
</FilmPostingDates>
</FilmPosting>
</FilmPostings>
</Film>
</Films>
</QueriesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
這裏是我的轉變:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://schemas.Movies.com/Movies"
xmlns:m="http://schemas.Movies.com/Movies"
exclude-result-prefixes="m"
>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<!-- standard identity template -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- This is mean to compare PostDate and ActiveDate, matching if different. It doesn't match any nodes in XML (but should match the final one). -->
<xsl:template match="m:Film[m:FilmPostings/m:FilmPosting/m:FilmPostingDates/m:FilmPostDate[1] [.!= m:FilmPostings/m:FilmPosting/m:FilmPostingDates/m:FilmActiveDate[1]]]">
</xsl:template>
<!-- This code does match the hard coded value (the second node). -->
<!--<xsl:template match="m:Film[m:FilmPostings/m:FilmPosting/m:FilmPostingDates/m:FilmPostDate[1] [.!= '2017-01-04T19:50:06.3830000-05:00']]">
</xsl:template>-->
</xsl:stylesheet>
所以,你在註釋掉位看,我可以做一個匹配的硬編碼值,所以我顯然是在正確的區域 - 我知道如果代碼找到匹配,它將排除整個Film節點。但它比較了兩個不起作用的節點值。
我在比較的右側嘗試了各種變體,但它似乎無法獲取ActiveDate的值。
你能確認你的邏輯究竟是什麼嗎?您是否想要移除'FilmPostDate'和'FilmActiveDate'相等的'Film'元素?謝謝! –
是的,我。硬編碼的例子做了一些不同的事情,但它向我確認這至少會排除A film節點。 –