Thursday, 16 October 2014

XPath (XSLT) match only specific structure



How do I match only a specific structure like:



<sandwich>
<bacon />
<lettuce />
<tomato />
</sandwich>


I want to replace it with something like



<sandwich>
<cheese />
<bacon />
<lettuce />
<tomato />
<mayo />
</sandwich>


But not effect any other similar "sandwiches", such as:



<sandwich>
<bacon />
<egg />
</sandwich>


More specifically, I have



<view>
<layout>
<sidebar>Some content and nodes</sidebar>
<content>Some more content and nodes</content>
</layout>
<layout>
<content>Some content and nodes</content>
<sidebar>Some more content and nodes</sidebar>
</layout>
</view>


And I want to transform it into:



<view>
<foo>
<bar>Some content and nodes</bar>
<baz>Some more content and nodes</baz>
</foo>
<layout>
<content>Some content and nodes</content>
<sidebar>Some more content and nodes</sidebar>
</layout>
</view>


(using XSLT)


No comments:

Post a Comment