|
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
|
|
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.
|
|
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 ), '/' )
|
|
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
|
|
guest |