I am trying to find a formula that creates a URL for an element based on its position in the XML hierarchy.
This is my xml example:
<Xml>
<Site Url="http://mysite.abc">
<Content></Content>
<SubSites>
<Site Url="/sub1">
<Content></Content>
<SubSites>
<Site Url="/sub2">
<Content></Content>
<SubSites>
<Site Url="/sub3">
<Content></Content>
</Site>
</SubSites>
</Site>
</SubSites>
</Site>
</SubSites>
</Site>
</Xml>
I have a function in Powershell that recursively iterates over the top and for each Content element, I want to generate a concatenation of Url values. Therefore, it must generate sequentially for each "Content" Node:
http:
http:
http:
http:
I am currently using as a start: ($ Node = 'Content' element)
$Sites = $Node | Select-XML -XPath "//ancestor::Site"
But for every $ Node, he selects all the elements of the site. He expected him to find more ancestors by going down in the xml structure.
If someone would know how to concatenate values directly using Xpath, that would be especially cool, but for a start I would be happy to know what is happening with my current approach.