IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

assemble string from recursive hierarchy Options · View
rip
Posted: Thursday, April 10, 2014 1:30:09 PM
Rank: Advanced Member

Joined: 7/17/2008
Posts: 185
Location: Minutiae, Triviality
I have an xsd that allows:

Code:
<foo name="one">
  <foo name="two">
    <foo name="...">
      <bar>
        <fnorb>hydrogen</fnorb>
      </bar>
      <bar>
        <fnorb>helium</fnorb>
      <bar>
    </foo>
...
</foo>


ie, an arbitrarily deep set of @name'd 'foo' elements with a sequence of bar elements innermost.

I'm trying for a finely crafted autocalc xpath that will return a concat xs:string value of /one/two/... for an arbitrary 'bar' element. The display would result in something like:

/one/two/...: hydrogen
/one/two/...: helium

Suggestions?

tia,
rip
rip
Posted: Saturday, April 12, 2014 7:01:48 PM
Rank: Advanced Member

Joined: 7/17/2008
Posts: 185
Location: Minutiae, Triviality
Brute forced it using a design fragment, effectively

if (exists(../../../../foo)) then concat("/", ../../../../@name) else ''
if (exists(../../../foo)) then concat("/", ../../../@name) else ''
if (exists(../../foo)) then concat("/", ../../@name) else ''
if (exists(../foo)) then concat("/", ../@name) else ''

since I know that it will never be more than four deep.

Still there should be a way to do this using a recursive template.


vlad
Posted: Sunday, April 13, 2014 5:46:04 PM
Rank: Advanced Member

Joined: 12/13/2005
Posts: 2,856
Location: Mauritius
Yes, recursive is possible - normally you would need to write a function for this which calls itself.

But in your particular case there is an even easier XPath (I've written it for the bar as starting element)

string-join(( ancestor::foo/@name, fnorb ), '/' )
rip
Posted: Monday, April 14, 2014 1:10:52 PM
Rank: Advanced Member

Joined: 7/17/2008
Posts: 185
Location: Minutiae, Triviality
Thanks, Vlad, that's sorted it.

I'd been trying with ancestor:: but couldn't stumble on the correct syntax.

[=AutoCalc]: [fnorb>(content)<fnorb]

with the AutoCalc xpath set to string-join( ('', ancester::foo/@name), '/' )

to get the exact output

/one/two/...: hydrogen
/one/two/...: helium
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.