Skip to content

Commit 72a32db

Browse files
committed
Fix support for outputting multiple element in the data transformer.
Fix the preview hint for the variable structure. Add more useful errors to the transformer.
1 parent 81b3549 commit 72a32db

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

StructuredXmlEditor/Data/DataTransformer.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ public bool TransformDocument(XElement root)
6767
var parent = el.Parent;
6868
var transformed = TransformElement(root, el);
6969

70-
el.ReplaceWith(transformed);
70+
foreach (var newEl in transformed)
71+
{
72+
el.AddBeforeSelf(newEl);
73+
}
74+
el.Remove();
7175
}
7276

7377
processed = true;
@@ -91,7 +95,11 @@ public bool TransformDocument(XElement root)
9195
var parent = el.Parent;
9296
var transformed = TransformElement(root, el);
9397

94-
el.ReplaceWith(transformed);
98+
foreach (var newEl in transformed)
99+
{
100+
el.AddBeforeSelf(newEl);
101+
}
102+
el.Remove();
95103
}
96104

97105
processed = true;
@@ -103,7 +111,7 @@ public bool TransformDocument(XElement root)
103111
}
104112

105113
//-----------------------------------------------------------------------
106-
public XElement TransformElement(XElement root, XElement originalEl)
114+
public IEnumerable<XElement> TransformElement(XElement root, XElement originalEl)
107115
{
108116
// split the template into variable chunks
109117
var template = OutputTemplate;
@@ -123,7 +131,7 @@ public XElement TransformElement(XElement root, XElement originalEl)
123131
{
124132
sourceEl = originalEl;
125133
}
126-
else if (variableSplit[1] == "root")
134+
else if (variableSplit[0] == "root")
127135
{
128136
sourceEl = root;
129137
}
@@ -166,6 +174,10 @@ public XElement TransformElement(XElement root, XElement originalEl)
166174
variableValue = targetEl.Value;
167175
}
168176
}
177+
else if (!string.IsNullOrWhiteSpace(variableSplit[2]))
178+
{
179+
throw new Exception("Unknown variable part type '" + variableSplit[2] + "'!");
180+
}
169181
else
170182
{
171183
variableValue = targetEl.ToString();
@@ -186,7 +198,7 @@ public XElement TransformElement(XElement root, XElement originalEl)
186198

187199
// parse expanded template into xelement
188200
var tempEl = XElement.Parse(fakeRoot);
189-
return tempEl.Elements().First();
201+
return tempEl.Elements();
190202
}
191203

192204
//-----------------------------------------------------------------------

StructuredXmlEditor/View/CustomControls/DataTransformerToolView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<TextBlock
9393
Grid.Row="2"
9494
Margin="5,5,5,0"
95-
Text="Replace template. Access content with {(el,root) | (path) | (content,name)}." />
95+
Text="Replace template. Access content with {(el,root) | (path) | (contents,name)}." />
9696
<local:PromptTextBox
9797
Grid.Row="3"
9898
AcceptsReturn="True"

0 commit comments

Comments
 (0)