Xsl: for-each select =: two conditions

in xsl we can write two conditions in a "for each" loop. for example, instead

<xsl:when test="/document/line[
                   (substring(field[@id='0'], 1,3)='MAR')
                ] and 
                /document/line[
                   contains(substring(field[@id='0'],123,4),'0010')
                ]">

we can write this:

<xsl:for-each select="/document/line[
                         contains(substring(field[@id='0'], 1,3),'MAR')
                      ] and 
                      /document/line[
                         contains(substring(field[@id='0'],123,4),'0010')
                      ]">

Regards

Update from comments

<xsl:for-each select="/document/line[
                         contains(substring(field[@id='0'], 1,3),'MAR') 
                         and contains(substring(field[@id='0'],123,4),'0010')
                      ]">
+3
source share
1 answer

If the question is, “is it possible to check the two conditions in the select attribute for each”, the answer is: NO . Because the

The expression must be evaluated in node-set. (from ZVON )

Therefore, the select data type must be a node-set not a boolean.

But if you want to select two node sets inside xsl:for-eachor xsl:template(the latter is better), etc., you can use the union (|) operator

<xsl:for-each select="/document/line[
                         contains(substring(field[@id='0'], 1,3),'MAR')
                      ] | 
                      /document/line[
                         contains(substring(field[@id='0'],123,4),'0010')
                      ]">
+8

Source: https://habr.com/ru/post/1795685/


All Articles