存储对节点的引用(散列?)以进行条件操作

Storing reference (hash?) to the node for conditional manipulation

给出这个伪代码:

   <xsl:variable name="check0">
       <xsl:value-of select="($externalFile//i[@attibute = $variable]/../@start < $genDate) and
                             ($externalFile//i[@attibute = $variable]/../@stop  > $genDate)"/>
    </xsl:variable>


   <xsl:variable name="check1">
       <xsl:value-of select="($externalFile//i[@attibute = $variable]/../@start < $genDate) and
                             ($externalFile//i[@attibute = $variable]/../@stop  > $genDate)"/> 
   </xsl:variable>

以上代码检查某些变量是否在从外部 .xml 文件

获取的属性的日期范围内

有没有办法存储对文件的引用,这样:

$externalFile//i[@attibute = $variable] 查找没有发生 4 次?

像这样:

<xsl:variable name="check3">
    <xsl:value-of select="($externalFile//i[@attibute = $variable]/>
</xsl:variable>

<xsl:if $check3/../@start > someValue />
<xsl:if $check3/../@stop  < someValue />

<xsl:variable name="outcome">
    <xsl:value-of select="$check3/../@price"/> // <-- retrive some data 
</xsl:variable>

答案是"Yes"。您只需将 check3 变量更改为:

<xsl:variable name="check3" select="$externalFile//i[@attibute = $variable]" />

这样你就可以直接在外部文件中引用 i 节点,而不是获取它的文本值(这是 xsl:value-of 会做的)