/// <summary>
        ///
        /// </summary>
        protected override void Apply()
        {
            if (TargetChildNodes == null || TargetChildNodes.Count == 0)
            {
                TargetNode.AppendChild(TransformNode);
            }
            else
            {
                XmlAttribute transformAtt = null;

                foreach (XmlAttribute att in TransformNode.Attributes)
                {
                    if (string.Equals(att.Name, AttributeName, StringComparison.OrdinalIgnoreCase))
                    {
                        transformAtt = att;
                        break;
                    }
                }

                if (transformAtt == null)
                {
                    throw new InvalidOperationException("No target attribute to append");
                }

                foreach (XmlNode targetNode in TargetChildNodes)
                {
                    var foundAttribute = false;
                    foreach (XmlAttribute att in targetNode.Attributes)
                    {
                        if (string.Equals(att.Name, AttributeName, StringComparison.OrdinalIgnoreCase))
                        {
                            foundAttribute = true;
                            if (string.IsNullOrEmpty(att.Value))
                            {
                                att.Value = transformAtt.Value;
                            }
                            else
                            {
                                // TODO: This doesn't compose well with insertOrAppend being applied on the TargetNode.
                                // The target node is created with the children it has in the transform, which means we would
                                // duplicate the value here.
                                if (att.Value == transformAtt.Value)
                                {
                                    return;
                                }
                                att.Value = $"{att.Value};{transformAtt.Value}";
                            }
                        }
                    }

                    if (!foundAttribute)
                    {
                        var attribute = targetNode.OwnerDocument.CreateAttribute(AttributeName);
                        attribute.Value = transformAtt.Value;
                        targetNode.Attributes.Append(attribute);
                    }
                }
            }
        }
Beispiel #2
0
        protected override void Apply()
        {
            CommonErrors.ExpectNoArguments(Log, TransformNameShort, ArgumentString);

            TargetNode.AppendChild(TransformNode);

            Log.LogMessage(MessageType.Verbose, Resources.XMLTRANSFORMATION_TransformMessageInsert, TransformNode.Name);
        }
Beispiel #3
0
 protected override void Apply()
 {
     CommonErrors.ExpectNoArguments(Log, TransformNameShort, ArgumentString);
     if (TargetChildNodes is null || TargetChildNodes.Count == 0)
     {
         TargetNode.AppendChild(TransformNode);
         Log.LogMessage(MessageType.Verbose, SR.XMLTRANSFORMATION_TransformMessageInsert, TransformNode.Name);
     }
 }