@@ -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 //-----------------------------------------------------------------------
0 commit comments