Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xsl:for-each select=: two conditions

Tags:

xslt

in xsl we can write two condition in cycle "for each". for example instead of

<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 it:

<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')
                      ]">

Best 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')
                      ]">
like image 700
Petras Avatar asked Dec 29 '22 00:12

Petras


1 Answers

If the question is "is it possible to check 2 conditions in a select attribute of a for-each" the answer is: NO. Because

The expression must evaluate to a node-set. (from ZVON)

Hence the data type of the select must be a node-set not a boolean value.

But, if you want to select two node-sets inside a xsl:for-each or 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')
                      ]">
like image 103
bluish Avatar answered Jan 14 '23 01:01

bluish