XML Script logo
Using inheritance
Code
<_data >
	<inheri test="working" >
		<sub />
		<sub >
			<down >
				<down2 >
					<down3 >
						<down4 >
						</down4>
					</down3>
				</down2>		
			</down>
		</sub>
		
		<sub />
	</inheri>
</_data>
At this point the attribute test is only in exsistence in element inheri

#inheri\sub[2].test := "working2"#
Now test in second element called sub has also been set

should be "working" after this text      #inheri!test#
this will print out inheri.test as test has a value in inheri

should be blank after this text          #inheri\sub[1].test#
test does not have a value in inheri\sub[1] so and we have not used ! so this will be blank

should be "working" after this text      #inheri\sub[1]!test#
test still does not have a value but we have used ! so it will look at its parent and therefore retrieve the value from inheri

should be "working2" after this text     #inheri\sub[2]!test#
inheri\sub[2]!test does have a value so even though we have used ! it will retrieve it from inheri\sub[2]

#inheri\sub[3]!test := "working3"#
we have set test in inheri\sub[3] with !. This element does not have a test attribute so it will look at its parent and set it there if possible

should be blank after this text          #inheri\sub[3].test#
inheri\sub[3] still does not have a test element

should be "working3" after this text     #inheri.test#
this has been set to "working3" be the ! assignment 2 interpolations up

should be "working3" after this text     #inheri\sub[3]!test#
inheri\sub[3] does not have a test element and we have used bang so it will retrieve a value from its parents

#inheri\sub[3].test := "working4"#
should be "working4" after this text     #inheri\sub[3]!test#
now we create a test attribute in inheri\sub[3] and print it out

<_delete item="inheri\sub[3].test" />
we can remove an attribute as well

should be "working3" after this text     #inheri\sub[3]!test#
now the value comes from the parent inheri again

<_delete item="inheri.test" />
we remove the test attribute of inheri

should be blank after this text          #inheri\sub[1]!test#
now test can not be retrieved from inheri so it is blank

should be "working2" after this text     #inheri\sub[2].test#
inheri\sub[2] still has a value and can be printed out

#inheri.test := "working"#
reset inheri.test

<_delete item="inheri\sub[1]!test" />
we can also ! delete - inheri\sub[1] does not have a test so it will look at the parent and delete it from there

should be blank after this test		#inheri\sub[1]!test#
now this will be blank as neither inheri\sub[1] or inheri have test attributes
should be be "working2" after this text   #inheri\sub[2]\down\down2\down3\down4!test#
the ! works on as many levels as we wish recursivly so will print "working2" as inheri\sub[2].test is "working2"
Output
At this point the attribute test is only in exsistence in element inheri

Now test in second element called sub has also been set

should be "working" after this text      working
this will print out inheri.test as test has a value in inheri

should be blank after this text          
test does not have a value in inheri\sub[1] so and we have not used ! so this will be blank

should be "working" after this text      working
test still does not have a value but we have used ! so it will look at its parent and therefore retrieve the value from inheri

should be "working2" after this text     working2
inheri\sub[2]!test does have a value so even though we have used ! it will retrieve it from inheri\sub[2]

we have set test in inheri\sub[3] with !. This element does not have a test attribute so it will look at its parent and set it there if possible

should be blank after this text          
inheri\sub[3] still does not have a test element

should be "working3" after this text     working3
this has been set to "working3" be the ! assignment 2 interpolations up

should be "working3" after this text     working3
inheri\sub[3] does not have a test element and we have used bang so it will retrieve a value from its parents

should be "working4" after this text     working4
now we create a test attribute in inheri\sub[3] and print it out

we can remove an attribute as well

should be "working3" after this text     working3
now the value comes from the parent inheri again

we remove the test attribute of inheri

should be blank after this text          
now test can not be retrieved from inheri so it is blank

should be "working2" after this text     working2
inheri\sub[2] still has a value and can be printed out

reset inheri.test

we can also ! delete - inheri\sub[1] does not have a test so it will look at the parent and delete it from there

should be blank after this test		
now this will be blank as neither inheri\sub[1] or inheri have test attributes
should be be "working2" after this text   working2
the ! works on as many levels as we wish recursivly so will print "working2" as inheri\sub[2].test is "working2"
Ref

x.5901

XML Script homepage | Documentation home | XML Script docs | Command list | Function list | X-Tract docs

X-Stream, X-Tract and XML Script are trade marks of DecisionSoft Limited
© Copyright 1998-2000 DecisionSoft Limited