我有這樣的XML文件中刪除一些節點在一個XML文件:如何篩選和使用sxlt
<A>
<B>
<elt>Add</elt>
...there are some element here
<bId>2</bId>
</B>
<B>
<elt>Add</elt>
...there are some element here
<bId>2</bId>
</B>
<B>
<elt>Add</elt>
...there are some element here
<bId>2</bId>
</B>
<B>
<elt>can</elt>
...there are some element here
<bId>3</bId>
</B>
<B>
<elt>can</elt>
...there are some element here
<bId>3</bId>
</B>
我要檢查每個投標元素的值。如果這個值與之前或之後的元素相同,那麼我會將其他元素的區塊放入另一個區塊,例外元素bId這將在轉換後被拒絕。要通過你讓我的問題的理解,這裏是預期的輸出:
<CA>
<cplx>
<spRule>
<elt>Add</elt>
...
</spRule>
<spRule>
<elt>Add</elt>
...
</spRule>
<spRule>
<elt>Add</elt>
...
</spRule>
</cplx>
<cplx>
<spRule>
<elt>can</elt>
...
</spRule>
<spRule>
<elt>can</elt>
...
</spRule>
</cplx>
</CA>
即使當在XML文件中的元素不被的的值排序投標,我想也得到了相同的預期輸出。 我嘗試使用這個XSL代碼:
<xsl:for-each select="bId"
<CA>
<cplx>
<xsl:choose>
<xsl:when test="node()[preceding::bId]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:when>
</cplx>
</CA>
</xsl:for-each>
,但它不走。請有人幫助我嗎? 感謝
請詳細說明「時,在XML文件中的元素不受出價的價值排序,我想也得到了相同的預期輸出」,這聽起來就好像你對mply想要將具有某個「bId」值的所有元素進行分組,而前面的描述「如果此值與前面或後面的值相同」聽起來像是不同的要求,即只對相鄰元素進行分組。 –
你好馬丁。我真的想將所有具有** bId **值的元素分組,即使這些元素沒有排序。例如,我們在xml中有** bId **的這些值:2,2,3,2,2 ...然後,我將首先將所有具有值** bId ** = 2的元素分組在一起,休息在另一個集團。 –
請參閱我的答案中的第二個示例,您只需要對其進行分組,然後在XSLT 1.0中使用http://www.jenitennison.com/xslt/grouping/muenchian.xml完成分組。 –