2017-06-24 161 views
0

此代碼來自我發送的補充xsl,當我告訴我的客戶端配置文件在標題中錯誤地將「Northern Ireland」排除在外時。現在,他把它全部帶回來了,但我需要排除一些結果 - 下面顯示了一個例子。從xsl中排除結果

我想篩選出的結果的對象的識別信息是nisr內部affectingURI e.g.key-33793274a92a1f194b3ebcfccfc08927在XML張貼在端。

我該如何擺脫這些'nisr'結果?

<xsl:template match="atom:feed" mode="results"> 
    <xsl:apply-templates select="atom:entry/ukm:Effect"/> 
</xsl:template> 
<xsl:template match="ukm:Effect"> 
    <xsl:choose> 
     <xsl:when test="@Type= 'Commencement Order' and @AffectedProvisions='specified amended provision(s)'"/> 
     <xsl:when test="contains(ukm:AffectingTitle[1], 'Northern Ireland')"/> 
     <xsl:when test="contains(ukm:AffectingTitle[1], 'Northern-Ireland')"/> 
     <xsl:when test="contains(ukm:AffectedTitle[1], 'Northern Ireland')"/> 
     <xsl:when test="contains(ukm:AffectedTitle[1], 'Northern-Ireland')"/> 
     <xsl:when test="@Type= 'coming into force'"/> 
     <xsl:otherwise> 
      <tr xsl:exclude-result-prefixes="atom xs xhtml tso db sls ukm"> 
       <xsl:apply-templates select="." mode="resultsAffectedYearNumber"/> 
       <xsl:apply-templates select="." mode="resultsAffectedTitle"/> 
       <xsl:apply-templates select="." mode="resultsChangedProvision"/> 
       <xsl:apply-templates select="." mode="resultsAffectingTitle"/> 
       <xsl:apply-templates select="." mode="resultsInForceDates"/> 
       <xsl:apply-templates select="." mode="resultsEffectId"/> 
      </tr> 
     </xsl:otherwise> 
    </xsl:choose> 

這裏是源代碼。

- 我希望在我的結果中沒有任何關於「key-33793274a92a1f194b3ebcfccfc08927」的內容,因爲它包含NISR。

- 如果你能幫助我排除NISR,我會採取同樣的邏輯,並應用到「關鍵e789d8aa9e46169ba1f49655051c66d1」,因爲NIA也affectingURI是六個把手我需要省略

-The英國一個pga(英國公衆和一般行爲,對於那些想知道他們在看什麼的人)結果(「key-fce2f92caeab329b0d33dfb1adca9bdf」)將包括在內。我在替換配置之前的起點是缺少了這一點,因爲它在冠軍頭銜中有北愛爾蘭,而在某些我無法識別的地方,這被錯誤地排除在外。作者應該只排除NIA,NISR和NISI。

<entry> 
          <id>http://www.legislation.gov.uk/changes/affected/ukpga/1972/18/affecting/nisr/2016/387/modified/2017-01-19T15:31:27Z</id> 
          <title>The Justice (2015 Act) (Commencement No. 7 and Saving Provisions) Order (Northern Ireland) 2016 effect on Maintenance Orders (Reciprocal Enforcement) Act 1972</title> 
          <updated>2017-01-19T15:31:27Z</updated> 
          <author><name/></author> 
          <ukm:Effect EffectId="key-33793274a92a1f194b3ebcfccfc08927" AffectedClass="UnitedKingdomPublicGeneralAct" AffectedURI="http://www.legislation.gov.uk/id/ukpga/1972/18" AffectingURI="http://www.legislation.gov.uk/id/nisr/2016/387" AffectingClass="NorthernIrelandStatutoryRule" URI="http://www.legislation.gov.uk/id/effect/key-33793274a92a1f194b3ebcfccfc08927" Row="70" Type="Commencement Order" Applied="false" RequiresApplied="true" AffectedProvisions="specified amended provision(s)" Notes="commencement order for 2015 c. 9 (N.I.)" AffectingYear="2016" AffectingNumber="387" AffectingProvisions="art. 2" AffectedYear="1972" AffectedNumber="18" Modified="2017-01-19T15:31:27Z"><ukm:AffectedTitle>Maintenance Orders (Reciprocal Enforcement) Act 1972</ukm:AffectedTitle><ukm:AffectedProvisions>specified amended provision(s)</ukm:AffectedProvisions><ukm:AffectingTitle>The Justice (2015 Act) (Commencement No. 7 and Saving Provisions) Order (Northern Ireland) 2016</ukm:AffectingTitle><ukm:AffectingProvisions><ukm:Section Ref="article-2" URI="http://www.legislation.gov.uk/id/nisr/2016/387/article/2">art. 2</ukm:Section></ukm:AffectingProvisions><ukm:Commenced>commencement order for <ukm:Citation Class="NorthernIrelandAct" URI="http://www.legislation.gov.uk/id/nia/2015/9" Year="2015" Number="9" Title="Justice Act (Northern Ireland) 2015">2015 c. 9 (N.I.)</ukm:Citation></ukm:Commenced><ukm:InForceDates><ukm:InForce Applied="false" Prospective="true" Qualification=""/></ukm:InForceDates></ukm:Effect> 
         </entry><entry> 
          <id>http://www.legislation.gov.uk/changes/affected/ukpga/1973/36/affecting/nia/2016/4/modified/2016-03-25T09:47:14Z</id> 
          <title>Public Services Ombudsman Act (Northern Ireland) 2016 effect on Northern Ireland Constitution Act 1973</title> 
          <updated>2016-03-25T09:47:14Z</updated> 
          <author><name/></author> 
          <ukm:Effect EffectId="key-e789d8aa9e46169ba1f49655051c66d1" AffectedURI="http://www.legislation.gov.uk/id/ukpga/1973/36" AffectedClass="UnitedKingdomPublicGeneralAct" AffectingURI="http://www.legislation.gov.uk/id/nia/2016/4" AffectingClass="NorthernIrelandAct" URI="http://www.legislation.gov.uk/id/effect/nia-2016-4-4ds9a6o2-90" Row="90" Type="repealed" Applied="false" RequiresApplied="true" AffectedProvisions="s. 36(1)(a)(b)" AffectingEffectsExtent="NI" AffectingYear="2016" AffectingNumber="4" AffectingProvisions="Sch. 9" AffectedYear="1973" AffectedNumber="36" Created="2016-03-25T09:47:14Z" Modified="2016-03-25T09:47:14Z"><ukm:AffectedTitle>Northern Ireland Constitution Act 1973</ukm:AffectedTitle><ukm:AffectedProvisions><ukm:Section Ref="section-36-1-a" URI="http://www.legislation.gov.uk/id/ukpga/1973/36/section/36/1/a">s. 36(1)(a)</ukm:Section><ukm:Section Ref="section-36-1-b" URI="http://www.legislation.gov.uk/id/ukpga/1973/36/section/36/1/b">(b)</ukm:Section></ukm:AffectedProvisions><ukm:AffectingTitle>Public Services Ombudsman Act (Northern Ireland) 2016</ukm:AffectingTitle><ukm:AffectingTitle>Public Services Ombudsman Act (Northern Ireland) 2016</ukm:AffectingTitle><ukm:AffectingProvisions><ukm:Section Ref="schedule-9" URI="http://www.legislation.gov.uk/id/nia/2016/4/schedule/9">Sch. 9</ukm:Section></ukm:AffectingProvisions><ukm:CommencementAuthority><ukm:Section Ref="section-64" URI="http://www.legislation.gov.uk/id/nia/2016/4/section/64">s. 64</ukm:Section></ukm:CommencementAuthority><ukm:InForceDates><ukm:InForce Applied="false" Date="2016-04-01" Qualification="wholly in force"/></ukm:InForceDates></ukm:Effect> 
         </entry><entry> 
          <id>http://www.legislation.gov.uk/changes/affected/ukpga/1974/37/affecting/ukpga/2016/25/modified/2017-04-10T10:13:36Z</id> 
          <title>Investigatory Powers Act 2016 effect on Health and Safety at Work etc. Act 1974</title> 
          <updated>2017-04-10T10:13:36Z</updated> 
          <author><name/></author> 
          <ukm:Effect EffectId="key-fce2f92caeab329b0d33dfb1adca9bdf" AffectedClass="UnitedKingdomPublicGeneralAct" AffectedURI="http://www.legislation.gov.uk/id/ukpga/1974/37" AffectingURI="http://www.legislation.gov.uk/id/ukpga/2016/25" AffectingClass="UnitedKingdomPublicGeneralAct" URI="http://www.legislation.gov.uk/id/effect/key-fce2f92caeab329b0d33dfb1adca9bdf" Row="10" Type="inserted" Applied="false" RequiresApplied="true" AffectedProvisions="s. 20(9)(10)" AffectingEffectsExtent="E+W+S+N.I." AffectingYear="2016" AffectingNumber="25" AffectingProvisions="Sch. 2 para. 1" AffectedYear="1974" AffectedNumber="37" Modified="2017-04-10T10:13:36Z"><ukm:AffectedTitle>Health and Safety at Work etc. Act 1974</ukm:AffectedTitle><ukm:AffectedProvisions><ukm:Section Ref="section-20-9" URI="http://www.legislation.gov.uk/id/ukpga/1974/37/section/20/9" FoundRef="section-20">s. 20(9)</ukm:Section><ukm:Section Ref="section-20-10" URI="http://www.legislation.gov.uk/id/ukpga/1974/37/section/20/10" FoundRef="section-20">(10)</ukm:Section></ukm:AffectedProvisions><ukm:AffectingTitle>Investigatory Powers Act 2016</ukm:AffectingTitle><ukm:AffectingTitle>Further Education) Order (Northern Ireland) 2016</ukm:AffectingTitle><ukm:AffectingProvisions><ukm:Section Ref="schedule-2" URI="http://www.legislation.gov.uk/id/ukpga/2016/25/schedule/2">Sch. 2 </ukm:Section><ukm:Section Ref="schedule-2-paragraph-1" URI="http://www.legislation.gov.uk/id/ukpga/2016/25/schedule/2/paragraph/1">para. 1</ukm:Section></ukm:AffectingProvisions><ukm:Savings><ukm:Section Ref="schedule-9" URI="http://www.legislation.gov.uk/id/ukpga/2016/25/schedule/9">Sch. 9 </ukm:Section><ukm:Section Ref="schedule-9-paragraph-7" URI="http://www.legislation.gov.uk/id/ukpga/2016/25/schedule/9/paragraph/7">paras. 7</ukm:Section> <ukm:Section Ref="schedule-9-paragraph-8" URI="http://www.legislation.gov.uk/id/ukpga/2016/25/schedule/9/paragraph/8">8</ukm:Section> <ukm:Section Ref="schedule-9-paragraph-10" URI="http://www.legislation.gov.uk/id/ukpga/2016/25/schedule/9/paragraph/10">10</ukm:Section></ukm:Savings><ukm:CommencementAuthority><ukm:Section Ref="section-272-1" URI="http://www.legislation.gov.uk/id/ukpga/2016/25/section/272/1">s. 272(1)</ukm:Section></ukm:CommencementAuthority><ukm:InForceDates><ukm:InForce Applied="false" Prospective="true" Qualification=""/></ukm:InForceDates></ukm:Effect> 
         </entry> 
+0

你的問題不明確。請發佈一個可重複的例子,包括輸入和期望的輸出 - 請參閱:[mcve]。 –

+0

我將刪除此問題併發布整段代碼。謝謝。 – mynameisred

+0

哦,不允許發佈另一個半小時... – mynameisred

回答

0

我不知道如果我完全理解這個問題,但是當你說「我想篩選出的結果是nisr內affectingURI」,然後一個方法來解決這個問題是通過使用模板匹配排除事物。

您目前有一個模板匹配ukm:Effect它匹配所有的這些命名的元素

<xsl:template match="ukm:Effect"> 

如果你有一個規則的ukm:Effect元素將被排除在外,其中nisr裏面affectingURI,您應添加其他模板,像這樣

<xsl:template match="ukm:Effect[contains(@AffectingURI, '/nisr/')]" /> 

因爲這個模板有那麼元素名稱後的條件,這將有更高的優先級,其他模板,導致ukm:Effect元素是排除。

所以,與其具有xsl:choose/xsl:when排除元素...

<xsl:when test="contains(ukm:AffectingTitle[1], 'Northern Ireland')"/> 

你可以改寫這個爲模板匹配排除

<xsl:template match="ukm:Effect[contains(ukm:AffectingTitle[1], 'Northern Ireland')]"/> 

警惕不過,模板匹配ukm:Effect[contains(ukm:AffectingTitle[1], 'Northern Ireland')]將具有與匹配ukm:Effect[contains(@AffectingURI, '/nisr')]的模板相同的優先級(因爲兩者都有條件)。如果兩個模板可以匹配具有相同優先級的相同元素,則認爲是錯誤的。您可能需要粘在第二模板priority屬性在這種情況下

<xsl:template match="ukm:Effect[contains(@AffectingURI, '/nisr')]" priority="2" /> 

或者,你可以一個模板,一個大的條件檢查

<xsl:template match="ukm:Effect[contains(@AffectingURI, '/nisr/') or contains(ukm:AffectingTitle[1], 'Northern Ireland')]"/> 
+0

所有真的有幫助的,謝謝,我會有一個bash--整個過程需要近一個小時才能完成,所以當我玩耍的時候我會安靜下來的,唯一不能確定的是我希望排除nisr。沒有看到任何「不包含」或!所以我想也許我已經把這個問題弄糊塗了。我認爲你的有用建議要求xsl包含nisr,不是嗎?有關如何排除它的任何提示?謝謝再次 – mynameisred

+0

當'@ AffectingURI'包含'/ nisr /'時,將使用模板''如果您看到,這是自閉的,所以什麼都不會做,這會忽略該元素的影響,從而將它排除在輸出之外。 –

+0

非常感謝用你的幫助。我擔心,雖然你的意見是有道理的,並且增加了我的知識,但我的問題沒有解決,所以我回到了客戶端,並且會等待他們糾正什麼 - 畢竟 - 他們的錯誤。再次感謝。 – mynameisred