2017-08-29 72 views
0

我正在嘗試將xslt節點與name=SomeName2並獲取其孩子節點文本作爲輸出。我不知道它們在xml文件中的位置,它們在不同的xml文件中的位置總是不同的。搜索具有特定名稱標籤的節點

是否有一個選項可以研究節點名稱的xml文件,而不是節點名稱空間?

這裏我的XML文件:

<con1:node>    
       <con2:node name="SomeName"> 
        <con2:path>'Text'</con2:path> 
       </con2:node> 
       <con2:node name="SomeName2"> 
        <con2:path>'Text'</con2:path> 
       </con2:node> 
       <con2:node name="SomeName3"> 
        <con2:path>'Text'</con2:path> 
       </con2:node> 
<con1:node> 

回答

1

你可以使用:

<?xml version="1.0" encoding="UTF-8"?> 
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     version="2.0"> 
     <xsl:output indent="yes" method="text"/> 
     <xsl:template match="/"> 
      <xsl:value-of select="//@name[normalize-space(.) = 'SomeName2']/parent::*"/> 
     </xsl:template> 
    </xsl:stylesheet> 
+0

燦爛,非常感謝! – MypR

+0

這就是做'// @ name [normalize-space(。)='SomeName2']/parent :: *'?爲什麼不''// [@ name ='SomeName2']'? – Tomalak

相關問題