I am using XSLT 2.0. My desired output should have unique epc element values without any duplicate.
I need to compare all the child elements as see if there are any duplicates
<EPCISDocument xmlns:cbvmda="urn:epcglobal:cbv:mda"
xmlns:ns5="urn:epcglobal:epcis:xsd:1" schemaVersion="1.2"
creationDate="2020-02-21T19:14:36.974Z"
xmlns="urn:epcglobal:epcis:xsd:1">
<EPCISBody xmlns="">
<EventList>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546566</epc>
<epc>100002546567</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546566</epc>
<epc>100002546567</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546568</epc>
<epc>100002546569</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546568</epc>
<epc>100002546570</epc>
<epc>100002546571</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546571</epc>
<epc>100002546572</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546573</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546573</epc>
</epcList>
</ObjectEvent>
</EventList>
</EPCISBody>
</EPCISDocument>
My Output(Incorrect)
<?xml version = '1.0' encoding = 'UTF-8'?>
<ns6:EPCISDocument xmlns:ns6="urn:epcglobal:epcis:xsd:1">
<EPCISBody>
<EventList>
<ObjectEvent>
<epcList>
<epc>100002546566</epc>
<epc>100002546567</epc>
<action/>
</epcList>
</ObjectEvent>
<ObjectEvent>
<epcList>
<epc>100002546566</epc>
<epc>100002546567</epc>
<action/>
</epcList>
</ObjectEvent>
<ObjectEvent>
<epcList>
<epc>100002546568</epc>
<epc>100002546569</epc>
<action/>
</epcList>
</ObjectEvent>
<ObjectEvent>
<epcList>
<epc>100002546568</epc>
<epc>100002546569</epc>
<action/>
</epcList>
</ObjectEvent>
<ObjectEvent>
<epcList>
<epc>100002546568</epc>
<epc>100002546570</epc>
<epc>100002546571</epc>
<action/>
</epcList>
</ObjectEvent>
<ObjectEvent>
<epcList>
<epc>100002546568</epc>
<epc>100002546570</epc>
<epc>100002546571</epc>
<action/>
</epcList>
</ObjectEvent>
<ObjectEvent>
<epcList>
<epc>100002546571</epc>
<epc>100002546572</epc>
<action/>
</epcList>
</ObjectEvent>
<ObjectEvent>
<epcList>
<epc>100002546573</epc>
<action/>
</epcList>
</ObjectEvent>
</EventList>
</EPCISBody>
</ns6:EPCISDocument>
**Desired Output:**
<EPCISDocument xmlns:cbvmda="urn:epcglobal:cbv:mda"
xmlns:ns5="urn:epcglobal:epcis:xsd:1" schemaVersion="1.2"
creationDate="2020-02-21T19:14:36.974Z"
xmlns="urn:epcglobal:epcis:xsd:1">
<EPCISBody xmlns="">
<EventList>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546566</epc>
<epc>100002546567</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546568</epc>
<epc>100002546569</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546570</epc>
<epc>100002546571</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546572</epc>
</epcList>
</ObjectEvent>
<ObjectEvent>
<action>ADD</action>
<epcList>
<epc>100002546573</epc>
</epcList>
</ObjectEvent>
</EventList>
</EPCISBody>
</EPCISDocument>
**My XSLT**
<xsl:template match="/">
<ns6:EPCISDocument>
<EPCISBody>
<EventList>
<xsl:for-each-group select="/ns6:EPCISDocument/EPCISBody/EventList/ObjectEvent/epcList"
composite='yes' group-by="epc">
<ObjectEvent>
<epcList>
<xsl:for-each select="epc">
<epc>
<xsl:value-of select="."/>
</epc>
</xsl:for-each>
<action>
<xsl:value-of select="action"/>
</action>
</epcList>
</ObjectEvent>
</xsl:for-each-group>
</EventList>
</EPCISBody>
</ns6:EPCISDocument>
</xsl:template>
I am using XSLT 2.0.
My desired output should have unique epc element values without any duplicate.
I need to compare all the child elements as see if they are exact duplicates
If I'm understanding correctly, you could do this pretty easily with an xsl:key (see fiddle here)...
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="epc" match="epc" use="normalize-space()"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="
ObjectEvent[not(epcList/epc[count(.|key('epc',normalize-space())[1])=1])]|
epc[not(count(.|key('epc',normalize-space())[1])=1)]"/>
</xsl:stylesheet>
However, I'm not sure what's supposed to happen when an action other than "ADD" is encountered. (Right now, action is ignored.)
Related
I'm attempting to stream a video feed in a UWP application from a webpage created on another machine using flask. The page loads in MS Edge however when the webView is pointed to the page it gets stuck perpetually on the spinning wheel.
In the appxmanifest I've enabled Private Networks(Client & Server), Internet(Client & Server),
and Internet(Client).
I've also tried loading the page using a media player source pointed at the address which throws an error for an invalid address format.
The source for the webpage that I am attempting to load is the following:
<html>
<head>
<title></title>
</head>
<body>
<img src="/video_feed">
</body>
</html>
Any advice on what type of object I should be using to try and display the video feed would be much appreciated.
Thanks!
Edit:
Below is the source code and xaml for the page that is attempting to use the webView. Currently the image updates at 20 frames per second but this is likely to increase.
Thanks for your help.
namespace GroundControl.Views
{
public sealed partial class CameraPage : Page, INotifyPropertyChanged
{
DispatcherTimer updateDataTimer;
private const string DefaultUrl = "http://127.0.0.1";
private Uri _source;
public Uri Source
{
get { return _source; }
set { Set(ref _source, value); }
}
private bool _isLoading;
public bool IsLoading
{
get
{
return _isLoading;
}
set
{
if (value)
{
IsShowingFailedMessage = false;
}
Set(ref _isLoading, value);
IsLoadingVisibility = value ? Visibility.Visible : Visibility.Collapsed;
}
}
private Visibility _isLoadingVisibility;
public Visibility IsLoadingVisibility
{
get { return _isLoadingVisibility; }
set { Set(ref _isLoadingVisibility, value); }
}
private bool _isShowingFailedMessage;
public bool IsShowingFailedMessage
{
get
{
return _isShowingFailedMessage;
}
set
{
if (value)
{
IsLoading = false;
}
Set(ref _isShowingFailedMessage, value);
FailedMesageVisibility = value ? Visibility.Visible : Visibility.Collapsed;
}
}
private Visibility _failedMesageVisibility;
public Visibility FailedMesageVisibility
{
get { return _failedMesageVisibility; }
set { Set(ref _failedMesageVisibility, value); }
}
private void OnNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
IsLoading = false;
OnPropertyChanged(nameof(IsBackEnabled));
OnPropertyChanged(nameof(IsForwardEnabled));
}
private void OnNavigationFailed(object sender, WebViewNavigationFailedEventArgs e)
{
// Use `e.WebErrorStatus` to vary the displayed message based on the error reason
IsShowingFailedMessage = true;
}
private void OnRetry(object sender, RoutedEventArgs e)
{
IsShowingFailedMessage = false;
IsLoading = true;
webView.Refresh();
}
private async void OnOpenInBrowser(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(webView.Source);
}
public CameraPage()
{
InitializeComponent();
IsLoading = true;
Source = new Uri("http://192.168.1.100:5004");
}
public event PropertyChangedEventHandler PropertyChanged;
private void Set<T>(ref T storage, T value, [CallerMemberName]string propertyName = null)
{
if (Equals(storage, value))
{
return;
}
storage = value;
OnPropertyChanged(propertyName);
}
private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:behaviors="using:GroundControl.Behaviors"
xmlns:Custom="using:Microsoft.Toolkit.Uwp.UI.Controls"
x:Class="GroundControl.Views.CameraPage"
mc:Ignorable="d">
<Page.Resources>
<Style x:Key="BrowserButtonStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{ThemeResource ButtonForeground}" />
<Setter Property="BorderBrush" Value="{ThemeResource ButtonBorderBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
<Setter Property="Padding" Value="8,4,8,4" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="FocusVisualMargin" Value="-3" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="RootGrid" Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="RootGrid" />
</Storyboard>
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushPointerOver}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPointerOver}" />
</ObjectAnimationUsingKeyFrames>
<PointerUpThemeAnimation Storyboard.TargetName="RootGrid" />
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushPressed}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundPressed}" />
</ObjectAnimationUsingKeyFrames>
<PointerDownThemeAnimation Storyboard.TargetName="RootGrid" />
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushDisabled}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonForegroundDisabled}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter x:Name="ContentPresenter" AutomationProperties.AccessibilityView="Raw" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Content="{TemplateBinding Content}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Page.Style>
<StaticResource ResourceKey="PageStyle"/>
</Page.Style>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<WebView x:Name="webView" Source="{x:Bind Mode=OneWay, Path=Source}"
NavigationCompleted="OnNavigationCompleted"
NavigationFailed="OnNavigationFailed" />
<StackPanel Visibility="{x:Bind Mode=OneWay, Path=IsLoadingVisibility}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ProgressRing IsActive="{x:Bind Mode=OneWay, Path=IsLoading}" />
<TextBlock x:Uid="Camera_Loading" />
</StackPanel>
<StackPanel Visibility="{x:Bind Mode=OneWay, Path=FailedMesageVisibility}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" x:Uid="Camera_FailedMessage" TextWrapping="WrapWholeWords" />
<HyperlinkButton Click="OnRetry" x:Uid="Camera_Retry" HorizontalAlignment="Center" />
</StackPanel>
<Grid VerticalAlignment="Bottom" Background="{ThemeResource SystemControlChromeHighAcrylicElementMediumBrush}">
<StackPanel Orientation="Horizontal">
<Button IsEnabled="{x:Bind Mode=OneWay, Path=IsBackEnabled}" Style="{StaticResource BrowserButtonStyle}" Click="OnGoBack" x:Uid="Camera_BrowserBackButton">
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="" />
</Button>
<Button IsEnabled="{x:Bind Mode=OneWay, Path=IsForwardEnabled}" Style="{StaticResource BrowserButtonStyle}" Click="OnGoForward" x:Uid="Camera_BrowserForwardButton">
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="" />
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Style="{StaticResource BrowserButtonStyle}" Click="OnRefresh" x:Uid="Camera_RefreshBrowserButton">
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="" />
</Button>
<Button Style="{StaticResource BrowserButtonStyle}" Click="OnOpenInBrowser" x:Uid="Camera_OpenInBrowserButton">
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="" />
</Button>
</StackPanel>
</Grid>
<Custom:AdaptiveGridView x:Name="adaptiveGridView">
<StackPanel BorderBrush="Transparent" Height="370" Width="120">
<TextBlock x:Name="BatteryLabel" HorizontalAlignment="Left" Text="Battery: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="LatitudeLabel" HorizontalAlignment="Left" Text="Latitude: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="LongitudeLabel" HorizontalAlignment="Left" Text="Longitude: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="AbsAltitudeLabel" HorizontalAlignment="Left" Text="ABS Alt: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="RelAltitudeLabel" HorizontalAlignment="Left" Text="Rel Alt: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="VelNorthLabel" HorizontalAlignment="Left" Text="Vel North: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="VelEastLabel" HorizontalAlignment="Left" Text="Vel East: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="VelForwardLabel" HorizontalAlignment="Left" Text="Vel Forw: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="VelDownLabel" HorizontalAlignment="Left" Text="Vel Down: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="DistanceDownSenseLabel" HorizontalAlignment="Left" Text="Dist Down: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="YawAngleLabel" HorizontalAlignment="Left" Text="Yaw Angle: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="YawCamAngleLabel" HorizontalAlignment="Left" Text="Yaw Deg: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top"/>
<TextBlock x:Name="PitchCamAngleLabel" HorizontalAlignment="Left" Text="Pitch Deg: " Margin="5" TextWrapping="Wrap" VerticalAlignment="Top" Width="67"/>
</StackPanel>
</Custom:AdaptiveGridView>
</Grid>
</Page>
I use odoo 9 is I noticed that it does not have a control for the input format for example for the email field I can enter any character and it will consider it as an email address. So I wanted to know how I can control the input format for a field for example for the email field the presence of "# and the" are mandatory or for the code field VAT for partners the presence of "/" is mandatory .
template.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="stock assets mask ext" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/field_mask/static/src/css/mask.css"/>
<script type="text/javascript" src="/field_mask/static/src/js/widgets.js"></script>
<script type="text/javascript" src="/field_mask/static/src/lib/jquery.inputmask.bundle.js"></script>
</xpath>
</template>
</data>
partner_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="res_partner_view_purchase_buttons_TVA_RC" model="ir.ui.view">
<field name="name">num.TVA.RC.res.partner.view.purchase.</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='website']" position="after">
<field name="CodeTVA" select="1" placeholder="Code TVA" widget="mask" data-inputmask-mask="9999999/A/A/A/999" />
<field name="RC" select="1" placeholder="Num RC"/>
</xpath>
</field>
</record>
</data>
widgets.js
function openerp_field_mask_widgets(instance) {
instance.web.form.FieldMask = instance.web.form.FieldChar.extend({
template : "FieldMask",
render_value: function() {
var show_value = this.get_value();
var field = this;
if (!field.get("effective_readonly")) {
field.$el.find('input').val(show_value);
var mask = field.node.attrs.mask;
field.$el.find('input').inputmask(mask);
} else {
field.$(".oe_form_char_content").text(show_value);
}
},
get_value: function() {
val = this.get('value');
if (!val) {
return '';
}
return val;
},
});
instance.web.form.widgets.add('mask', 'instance.web.form.FieldMask');
}
openerp.field_mask = function(openerp) {
openerp.field_mask = openerp.field_mask || {};
openerp_field_mask_widgets(openerp);
}
You can make your own widget with inputMask by inheriting FieldChar and you can find usefull mudules at odoowidgets or field_mask
i am currently facing issue to set the backgroud color to yellow when alternate row is true
i have grid in which few columns background is set to different colour. i have set highlightlight alterate row is to true. i have also set the yellow background when record is selected.
<Window.Resources>
<ObjectDataProvider x:Key="CarData" ObjectType="{x:Type Cars:CarsBusinessLogic}" MethodName="GetCars" />
<Style TargetType="{x:Type igDP:DataRecordCellArea}" >
<Setter Property="BackgroundSelected" Value="#FFDB4C"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected}" Value="False">
<Setter Property="BackgroundActive" Value="Transparent"/>
<Setter Property="BorderActiveBrush" Value="Transparent"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type igDP:DataRecordPresenter}" >
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="drp_PreviewMouseLeftButtonDown"/>
</Style>
<Style TargetType="{x:Type igDP:DataRecordCellArea}" x:Key="RecordAlignment">
<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
<Setter Property="VerticalAlignment" Value="Top"></Setter>
<Setter Property="VerticalContentAlignment" Value="Top"></Setter>
<Setter Property="BackgroundActive" Value="#FFDB4C"/>
<Setter Property="BackgroundSelected" Value="#FFDB4C"/>
<Setter Property="BackgroundHover" Value="#7092BE"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DataItem.Hovered}" Value="True">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=BackgroundHover}"/>
<Setter Property="BackgroundAlternate" Value="{Binding RelativeSource={RelativeSource Self}, Path=BackgroundHover}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsSelected}" Value="False">
<Setter Property="BackgroundActive" Value="Transparent"/>
<Setter Property="BorderActiveBrush" Value="Transparent"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="ColumnStyle1" TargetType="{x:Type igDP:CellValuePresenter}" >
<Setter Property="Background" Value="#D8E4BC"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsSelected}" Value="True">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
<DataTrigger Binding="{Binding DataItem.IsActive}" Value="True">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsAlternate,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={ x:Type igDP:DataRecordCellArea}} }" Value="True">
<Setter Property="Background" Value="#EFF7DB" />
</DataTrigger>
<DataTrigger Binding="{Binding DataItem.Hovered}" Value="True">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontWeight" Value="Bold"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<ScrollViewer Name="view1">
<igDP:XamDataGrid
Width="490" DataSource="{Binding Source={StaticResource CarData}}" HorizontalAlignment="Left" Name="xamDataGrid1" VerticalAlignment="Top" >
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:RecordListControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:RecordListControl}">
<ScrollViewer CanContentScroll="true"
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Disabled" >
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</igDP:XamDataGrid.Resources>
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings AllowEdit="False" AllowFixing="No"
CellClickAction="SelectRecord"
CellHeight="25" AutoSizeOptions="All"
AutoSizeScope="RecordsInView"
CellContentAlignment="LabelAboveValueAlignLeft" />
</igDP:XamDataGrid.FieldSettings>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings SelectionTypeRecord="Single" ></igDP:FieldLayoutSettings>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Key="BrandLevel" Tag="Brand" >
<igDP:FieldLayout.Settings>
<igDP:FieldLayoutSettings HighlightAlternateRecords="True" ></igDP:FieldLayoutSettings>
</igDP:FieldLayout.Settings>
<igDP:FieldLayout.Fields>
<igDP:Field Name="Make"/>
<igDP:Field Name="Model" />
<igDP:Field Name="BasePrice" >
<igDP:Field.Settings>
<igDP:FieldSettings CellMinWidth="50" CellValuePresenterStyle="{StaticResource ColumnStyle1}">
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="Mileage"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</ScrollViewer>
</Grid>
To keep the yellow background when an alternate record is selected, set the CellValuePresenter background to Transparent. Something like this should do the trick.
<Style x:Key="CellBackgroundStyle" TargetType="{x:Type igDP:CellValuePresenter}" >
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
</Style.Triggers>
</Style>
I have a List component using Checkbox as ItemRenderer. Now the problem is there is no synch between checkbox and List selection.
When the checkbox is selected/desected, I want to update selectedIndices property of the List and vice versa. The list is allowing multiple selection.
Any sample code for this?
My code is as below:
Assign Itemrenderer in List component:
_list.itemRenderer=new ClassFactory(CheckBoxRenderer);
CheckBoxRenderer.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:CheckBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
label="{data.name}"
selected="{data.isSelected}">
</mx:CheckBox>
If I understood your problem correctly, here is my solution and the running example.
I added a data grid to let you see that the data provider is changed after user interaction.
//Application
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
[Bindable]private var dp:ArrayCollection = new ArrayCollection([
{name: "record01", isSelected: false},
{name: "record02", isSelected: true},
{name: "record03", isSelected: false}]);
protected function onClick(event:MouseEvent):void
{
myDG.dataProvider.dispatchEvent( new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
}
]]>
</fx:Script>
<s:VGroup x="10" y="10">
<s:List dataProvider="{dp}" itemRenderer="renderers.CheckBoxRenderer" click="onClick(event)"/>
<s:Spacer height="20"/>
<s:DataGrid id="myDG" height="120" dataProvider="{dp}">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="name" headerText="Name" width="70"/>
<s:GridColumn dataField="isSelected" headerText="IsSelected" width="90"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
</s:VGroup>
</s:Application>
//Renderer
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<fx:Script>
<![CDATA[
protected function onChangeEvent(event:Event):void
{
data.isSelected = !data.isSelected;
}
]]>
</fx:Script>
<s:CheckBox label="{data.name}" selected="{data.isSelected}" change="onChangeEvent(event)"/>
</s:ItemRenderer>
EDIT
As I mentioned the data grid was added only to show the changes in the data provider.
Here is the code without additional components.
You need to control the data provider through the debuger to see that it is being changed.
The button was added just to invoke the debugger on trace() line.
//Application without the grid
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import renderers.CheckBoxRenderer;
[Bindable]private var dp:ArrayCollection = new ArrayCollection([
{name: "record01", isSelected: false},
{name: "record02", isSelected: true},
{name: "record03", isSelected: false}]);
protected function onBtnClick(event:MouseEvent):void
{
trace();
}
]]>
</fx:Script>
<s:VGroup x="10" y="10">
<s:List dataProvider="{dp}" itemRenderer="renderers.CheckBoxRenderer"/>
<s:Button click="onBtnClick(event)"/>
</s:VGroup>
</s:Application>
EDIT2
If you want to restrict the max number of selected items have a look at this code. It works well by me. This time I inserted the itemRenderer in the List definition.
Here is the working example.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="{reculcSelectedCount()}">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var _selectedCount:int = 0;
[Bindable]private var dp:ArrayCollection = new ArrayCollection([
{name: "record01", isSelected: false},
{name: "record02", isSelected: true},
{name: "record03", isSelected: false},
{name: "record04", isSelected: false}]);
[Bindable]public function get selectedCount():int
{
return _selectedCount;
}
public function set selectedCount(value:int):void
{
_selectedCount = value;
}
protected function onClick(event:MouseEvent):void
{
reculcSelectedCount();
}
protected function reculcSelectedCount():void
{
selectedCount = 0;
for each (var item:Object in dp)
{
if (item.isSelected)
selectedCount++;
}
}
]]>
</fx:Script>
<s:VGroup x="10" y="10">
<s:List dataProvider="{dp}" click="onClick(event)">
<s:itemRenderer>
<fx:Component>
<mx:HBox>
<fx:Script>
<![CDATA[
protected function onChangeEvent(event:Event):void
{
data.isSelected = !data.isSelected;
}
]]>
</fx:Script>
<s:CheckBox id="cb" label="{data.name}" selected="{data.isSelected}" enabled="{data.isSelected || (!data.isSelected && (outerDocument.selectedCount < 2))}" change="onChangeEvent(event)"/>
</mx:HBox>
</fx:Component>
</s:itemRenderer>
</s:List>
</s:VGroup>
</s:Application>
To avoid having to hard code the child element names I want to remove, I'd like to make a dynamic process to remove child elements when a matching parent element name is found.
My XML file:
<A>
<B1>
<C>C</C>
<D>D</D>
<E>E</E>
<H>H</H>
<MOD>
<C>C</C>
<D>D</D>
<E>E</E>
<F>F</F>
<G>G</G>
</MOD>
</B1>
<B2>
<C>C</C>
<E>E</E>
<H>H</H>
<MOD>
<C>C</C>
<D>D</D>
<E>E</E>
<F>F</F>
<G>G</G>
</MOD>
</B2>
<B3>
<D>D</D>
<E>E</E>
<H>H</H>
<X>X</X>
<MOD>
<C>C</C>
<D>D</D>
<E>E</E>
<F>F</F>
<G>G</G>
<X>G</X>
</MOD>
</B3>
</A>
Desired output:
My XML file:
<A>
<B1>
<C>C</C>
<D>D</D>
<E>E</E>
<H>H</H>
<MOD>
<F>F</F>
<G>G</G>
</MOD>
</B1>
<B2>
<C>C</C>
<E>E</E>
<H>H</H>
<MOD>
<D>D</D>
<F>F</F>
<G>G</G>
</MOD>
</B2>
<B3>
<D>D</D>
<E>E</E>
<H>H</H>
<X>X</X>
<MOD>
<C>C</C>
<F>F</F>
<G>G</G>
</MOD>
</B3>
</A>
My XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:strip-space elements="*"/>
<!-- copy all nodes -->
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<!-- Remove child elements but keep parent element with same name -->
<xsl:template match="C[../ancestor::*/C]"/>
<xsl:template match="D[../ancestor::*/D]"/>
<xsl:template match="E[../ancestor::*/E]"/>
</xsl:stylesheet>
I think I can combine the remove element code like this
<xsl:template match="C|D|E[../ancestor::*/C|D|E]"/>
I'm not sure how to start, but I'm thinking the process would have to get the parent node names (C,D,E,H), cycle through the children comparing the parent node name to each child node name. When a match is found, remove the child element. Thanks.
As far as I can tell, this stylesheet does what you need. It produces output matching what you say you need by excluding elements that have a parent with a preceding sibling of the same name.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:strip-space elements="*"/>
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="*">
<xsl:if test="not(parent::*/preceding-sibling::*[name() = name(current())])">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
When this XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template
match="MOD/*[../../* = self::* or preceding-sibling::* = self::*]"/>
</xsl:stylesheet>
...is applied against the provided XML:
<A>
<B1>
<C>C</C>
<D>D</D>
<E>E</E>
<H>H</H>
<MOD>
<C>C</C>
<D>D</D>
<E>E</E>
<F>F</F>
<G>G</G>
</MOD>
</B1>
<B2>
<C>C</C>
<E>E</E>
<H>H</H>
<MOD>
<C>C</C>
<D>D</D>
<E>E</E>
<F>F</F>
<G>G</G>
</MOD>
</B2>
<B3>
<D>D</D>
<E>E</E>
<H>H</H>
<X>X</X>
<MOD>
<C>C</C>
<D>D</D>
<E>E</E>
<F>F</F>
<G>G</G>
<X>G</X>
</MOD>
</B3>
</A>
...the wanted result is produced:
<A>
<B1>
<C>C</C>
<D>D</D>
<E>E</E>
<H>H</H>
<MOD>
<F>F</F>
<G>G</G>
</MOD>
</B1>
<B2>
<C>C</C>
<E>E</E>
<H>H</H>
<MOD>
<D>D</D>
<F>F</F>
<G>G</G>
</MOD>
</B2>
<B3>
<D>D</D>
<E>E</E>
<H>H</H>
<X>X</X>
<MOD>
<C>C</C>
<F>F</F>
<G>G</G>
</MOD>
</B3>
</A>
Explanation:
The first template is the well-known Identity Template, which copies all nodes and attributes from the source document to the result document.
The second template overrides the first and effectively removes all children of <MOD> that:
have the same name as a previous sibling or
have the same name as a sibling of their <MOD> parent (an "uncle-or-aunt")