[英]How to test the condition with numerical and match any alphabet using XSLT 1.0
[英]XSLT 1.0: how to match nodes according to not completely defined condition?
我有這個樣本輸入文件:
<?xml version="1.0"?>
<graph>
<tag name="A_start0"/>
<tag name="A_end0"/>
<tag name="A_start1"/>
<vertex name="A"/>
<edge name="AB" />
<tag name="A_start2"/>
<tag name="tagA"/>
<vertex name="C"/>
<tag name="A_end2"/>
</graph>
我想提取所有包含start
詞的tag
節點,這些tag
節點后不跟具有相同名稱的節點,但是其中start
已被end
替換。
從我的輸入圖中,我想獲得: <tag name="A_start1"/>
我所擁有的信息是,有些tag
元素的名稱以“ A_start”和“ A_end”開頭,但是我沒有有關該數字的信息。跟隨名字。
我想我應該使用key
來做到這一點,但是我不知道該怎么做。
我認為無法使用單個XPath表達式來完成。 嘗試類似:
<xsl:template match="/graph">
<xsl:for-each select="tag[starts-with(@name, 'A_start')] ">
<xsl:if test="not(following-sibling::tag[@name=concat('A_end', substring-after(current()/@name, 'A_start'))])">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:template>
另外,您可以使用密鑰的想法去做:
<xsl:key name="end" match="tag[starts-with(@name, 'A_end')]" use="substring-after(@name, 'A_end')"/>
<xsl:template match="/graph">
<xsl:copy-of select="tag[starts-with(@name, 'A_start')][not(key('end', substring-after(@name, 'A_start')))]"/>
</xsl:template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.