xslt copy of all nodes to variable

后端 未结 2 1649
一向
一向 2021-01-23 04:15

How one can assign to variable a copy of another variable that contains a set of nodes? Here is my code:

    

        
相关标签:
2条回答
  • 2021-01-23 04:54

    That depends on if you use XSLT-1.0 or XSLT-2.0.

    In XSLT-1.0 the following quote is determinative:

    In XSLT 1.0 the result tree fragment (RTF) type is like a node-set, but it is really a second-class citizen. An RTF is what you get whenever you use xsl:variable to construct a temporary tree. The problem is that you can't then use an XPath expression to access the innards of this tree, unless you use a vendor-specific extension function, usually called something like node-set(), to convert the RTF into a first-class node-set (consisting of one root node).

    So in XSLT-1.0 you only get an RTF which cannot be queried with further XPath queries and is therefore unable to fulfill your desire.

    Returning to the core of your question, the following rules do apply according to your XSL version:

    • 1.0: <xsl:variable name="abc" select="..." /> --> queryable
    • 1.0: <xsl:variable name="bcd"><xsl:whatever-function>...</xsl:whatever-function> --> NOT queryable
    • 2.0: <xsl:variable name="abc" select="..." /> --> queryable
    • 2.0: <xsl:variable name="bcd"><xsl:whatever-function>...</xsl:whatever-function> --> queryable - does return all nodes in that variable as a tree.

    Synopsis: You cannot make a complexly constructed XSLT-1.0 variable contain a fully queryable subset of your tree!

    0 讨论(0)
  • 2021-01-23 05:02

    Looking at your XSLT fragment, it looks like you want the blines variable to contain all the E1EDL24 elements where HIPOS is not zero, and if no-such elements exist, it should contain all E1EDL24 where HIPOS is zero.

    If this is the case, instead of trying to copy the elements in the variables, you could define the blines variable as follows:

    <xsl:variable name="blines" select="$btchs|$lines[not($btchs)]" />
    

    This would reference the original elements in the source XML, rather than create a Result Tree Fragment, and so would still be queryable.

    0 讨论(0)
提交回复
热议问题