Is it possible to filter in several child nodes at the same time? Based on the example below, I would like the xslt to check whether the "blue attribute" value is not exists.
My XML:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<item>
<Date>2023-02-19</Date>
<Cars>Ford</Cars>
<SellTarget>A4+</SellTarget>
<Time>10:40:09</Time>
<avg>19.3464027998</avg>
<product>
<defaultmarkers>
<Markers>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks="Blue"/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
</Markers>
</defaultmarkers>
</product>
<firstmarkers/>
</item>
<item>
<Date>2023-02-19</Date>
<Cars>Ford</Cars>
<SellTarget>A4+</SellTarget>
<Time>11:21:56</Time>
<avg>32.7150023474</avg>
<product>
<defaultmarkers/>
</product>
<firstmarkers>
<Markers>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks="blue "/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
</Markers>
</firstmarkers>
</item>
<item>
<Date>2023-02-19</Date>
<Cars>Ford</Cars>
<SellTarget>A4+</SellTarget>
<Time>19:01:27</Time>
<avg>554.0289810087</avg>
<product>
<defaultmarkers>
<Markers>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks="Yellow"/>
<Marker remarks=""/>
<Marker remarks="Blue"/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
</Markers>
</defaultmarkers>
</product>
<firstmarkers>
<Markers>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks="blue"/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
</Markers>
</firstmarkers>
</item>
<item>
<Date>2023-02-20</Date>
<Cars>Opel</Cars>
<SellTarget>A4+</SellTarget>
<Time>15:01:02</Time>
<avg>65.6303001034</avg>
<product>
<defaultmarkers>
<Markers>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks="Yellow"/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks="Green"/>
<Marker remarks=""/>
</Markers>
</defaultmarkers>
</product>
<firstmarkers/>
</item>
<item>
<Date>2023-02-21</Date>
<Cars>Opel</Cars>
<SellTarget>A4+</SellTarget>
<Time>02:00:00</Time>
<avg>1.2954721559</avg>
<product>
<defaultmarkers/>
</product>
<firstmarkers>
<Markers>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks="Green"/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
<Marker remarks=""/>
</Markers>
</firstmarkers>
</item>
</data>
MY XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:template match="/">
<Workbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:CharSet="238" x:Family="Swiss" ss:Size="11"
ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s63" ss:Name="mydefault">
<Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
<Font ss:FontName="Verdana"/>
</Style>
<Style ss:ID="s62" ss:Name="Normal_">
<Font ss:FontName="Verdana" ss:Bold="1"/>
<Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
</Style>
<Style ss:ID="s67" ss:Parent="s63">
<Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
<NumberFormat ss:Format="yyyy\.mm\.dd"/>
</Style>
<Style ss:ID="s69" ss:Parent="s63">
<Alignment ss:Horizontal="Left" ss:Vertical="Center"/>
<Font ss:FontName="Verdana"/>
</Style>
<Style ss:ID="s72">
<Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
<NumberFormat ss:Format="[$-F400]h:mm:ss\ AM/PM"/>
</Style>
</Styles>
<Worksheet ss:Name="Report">
<Table>
<Column ss:Width="63.75"/>
<Column ss:Width="31.5"/>
<Column ss:Width="61.5"/>
<Column ss:Width="50.25"/>
<Column ss:Width="87.75"/>
<Column ss:Width="56.25"/>
<Row ss:AutoFitHeight="0" >
<!-- Date -->
<Cell ss:StyleID="s62">
<Data ss:Type="String">Date</Data>
</Cell>
<!-- Cars -->
<Cell ss:StyleID="s62">
<Data ss:Type="String">Cars</Data>
</Cell>
<!-- SellTarget -->
<Cell ss:StyleID="s62">
<Data ss:Type="String">SellTarget</Data>
</Cell>
<!-- Time -->
<Cell ss:StyleID="s62">
<Data ss:Type="String">Time</Data>
</Cell>
<!-- avg -->
<Cell ss:StyleID="s62">
<Data ss:Type="String">avg</Data>
</Cell>
</Row>
<xsl:for-each select="data/item[not(product/defaultmarkers/Markers/Marker[contains(translate(@remarks, $uppercase, $lowercase), 'blue')])]">
<Row ss:AutoFitHeight="0">
<!-- Date -->
<Cell ss:StyleID="s67">
<Data ss:Type="String">
<xsl:value-of select="Date"/>
</Data>
</Cell>
<!-- Cars -->
<Cell ss:StyleID="s67">
<Data ss:Type="String">
<xsl:value-of select="Cars"/>
</Data>
</Cell>
<!-- SellTarget -->
<Cell ss:StyleID="s67">
<Data ss:Type="String">
<xsl:value-of select="SellTarget"/>
</Data>
</Cell>
<!-- Time -->
<Cell ss:StyleID="s67">
<Data ss:Type="String">
<xsl:value-of select="Time"/>
</Data>
</Cell>
<!-- avg -->
<Cell ss:StyleID="s67">
<Data ss:Type="String">
<xsl:value-of select="avg"/>
</Data>
</Cell>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>
I tried "or" and "and" at "for-each", but they shouldn't be checked at the same time, but neither of them gave the result.
Is it possible the check at both nodes:
here: /data/item/product/defaultmarkers/Markers/Marker/@remarks
and here: /data/item/firstmarkers/Markers/Marker/@remarks
and just show that "item" where no "blue" value at the remarks attribute?
MY result:
Date Cars SellTarget Time avg
2023-02-19 Ford A4+ 11:21:56 32.7150023474
2023-02-20 Opel A4+ 15:01:02 65.6303001034
2023-02-21 Opel A4+ 02:00:00 1.2954721559
Expected result:
Date Cars SellTarget Time avg
2023-02-20 Opel A4+ 15:01:02 65.6303001034
2023-02-21 Opel A4+ 02:00:00 1.2954721559
Thank you, Regards.
Try:
<xsl:for-each select="item[not(product/defaultmarkers/Markers/Marker[contains(translate(@remarks, $uppercase, $lowercase), 'blue')] or firstmarkers/Markers/Marker[contains(translate(@remarks, $uppercase, $lowercase), 'blue')])]">
If there are no other Markers, you could shorten it to:
<xsl:for-each select="item[not(.//Marker[contains(translate(@remarks, $uppercase, $lowercase), 'blue')])]">