How to make the and operator in XSLT?

What is an example of a select select command using an operator ANDsimilar to the operator if, where condition 1 = true and condition 2 = true?

+3
source share
3 answers

Here is an example of how to use the composite select statement.

<?xml version="1.0" encoding="ISO-8859-1"?>
<A>
    <B>
        <C>1</C>
        <D>2</D>
    </B>
    <B>
        <C>1</C>
        <D>3</D>
     </B>
    <E>test</E>
</A>

and your current pattern match matches "E", then try the code below to select only B, where C = 1 and D = 3: for reading conditions C and D 1 = true and condition 2 = true

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" indent="yes"/>
    <xsl:template match="E">
        <xsl:value-of select="../B[C = 1][D = 3]"></xsl:value-of>
    </xsl:template>
    <xsl:template match="C"/>
    <xsl:template match="D"/>
</xsl:stylesheet>

Luck

+2
source

Here is one of the simplest examples :

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match=
    "num[. mod 2  = 0 and . mod 3 = 0]">
  <xsl:copy-of select="."/>
 </xsl:template>

 <xsl:template match="text()"/>
</xsl:stylesheet>

when this conversion is applied to this XML document:

<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>10</num>
</nums>

the desired, correct result is output:

<num>06</num>
+3
source

Use the AND operator:

<xsl:if test="a and b">
+1
source

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


All Articles