Xslt 获取元素的所有子节点

Xslt 获取元素的所有子节点,xslt,xslt-2.0,Xslt,Xslt 2.0,我有一个xml文件,在该文件上我将转换应用于特定元素,然后尝试获取忽略同一节点的所有子节点的text() <xml> <xrefline> <query>eligible individual</query> in respect of a qualified dependant at any time means a person who at that time

我有一个xml文件,在该文件上我将转换应用于特定元素,然后尝试获取忽略同一节点的所有子节点的text()

<xml>
    <xrefline>
              <query>eligible individual</query>
              in respect of a qualified dependant at any time means a person who at that time   
              <quote>
              <para> 
               <n>(a)</n> 
              <parap>resides with the qualified dependant,</parap>
             </para> 
              </quote>
       </xrefline>
     </xml>

合格个人
就合资格受养人而言,任何时候均指当时
(a)
与符合条件的受抚养人居住,
我的xslt模板如下所示,我希望提取所有text()并保留查询元素

<xsl:template match="query" >
<xsl:apply-templates select="../text()|../node()[self::query]|../node()[not(self::query)]/text()" ></xsl:apply-templates>
</xsl:template>

我的欲望输出应该是这样的

     <xml>
         <xrefline>
              <query>eligible individual</query>
              in respect of a qualified dependant at any time means a person who at that time (a) resides with the qualified dependant,
         </xrefline>
     </xml>

合格个人
就任何时候的合格受抚养人而言,指当时(a)与该合格受抚养人居住在一起的人,

我必须围绕
模板match=“query”
进行操作,然后返回以获得所需的结果。使用我上面的xslt,我得到的文本位于元素quote之外,但不是quote元素的子元素的文本。。。任何帮助或提示都将非常有用。

我将编写两个模板:

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* , node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="xrefline//*[not(self::query)]">
  <xsl:apply-templates/>
</xsl:template>


请参阅。

嗨,Martin,你的答案很准确,但不能在处理问题中提到的单个模板时完成。。。if将在更改代码之前等待,如果有人能提供帮助的话……还有Martin,我们是否有办法将外部参照线内容放入CDATA中,就像此符合条件的个人在任何时候与符合条件的受抚养人相关,指当时(a)与符合条件的受抚养人居住在一起的人,]]>Martin,我已经使用您的逻辑实现了代码,它运行良好。感谢使用
xsl:output
上的
cdatasectionelements=“xrefline”
属性创建CDATA节适用于纯文本元素。但是,如果需要在CDATA中标记元素,如
query
元素,则首先需要序列化该节点,这只能通过XSLT 2.0或XSLT 3.0中的扩展实现。如果你在这方面需要帮助,那么我建议你发布一个新问题。